目录
一、Shell
1.shell定义
shell是Linux系统中后台运行的一种特殊程序也可以理解成一种特殊的软件,提供了用户与内核进行交互操作的一种接口。
2.不同的shell环境
bash是linux里面默认的shell程序位于/bin/bash
[root@localhost ~]# echo $SHELL //显示当前shell
/bin/bash
[root@localhost ~]# cat /etc/shells //显示当前系统所有使用的shell
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
/bin/tcsh
/bin/csh
3.shell与内外部命令
shell 分为内部命令和外部命令,一般输入命令后先判断是内部命令还是外部命令。如果是内部命令,会直接执行。如果是外部命令,hash表会记录已使用的外部命令,先在hash表中查询,如果能查询到,直接执行(别名优先)。如果hash表中没有缓存此命令,则会在放命令的文件中依次检索,查询到之后执行,查询不到报错。
Linux默认规定命令放在指定的文件夹中:
/usr/local/sbin : /usr/local/bin : /usr/sbin : /usr/bin : /root/bin
内部命令 | 外部命令 |
集成于Shell解释器程序内部的一些特殊指令,也称为内建(Built-in)指令 | Linux系统中能够完成特定功能的脚本文件或二进制程序 |
属于Shell的一部分 | 属于Shell解释器程序之外的命令 |
没有单独对应的系统文件 | 每个外部命令对应了系统中的一个文件 |
自动载入内存,可以直接使用 | 必须知道其对应的文件位置,由Shell加载后才能执行 |
可以使用type命令查看命令类型
[root@localhost ~]# type useradd
useradd is /usr/sbin/useradd //useradd是外部命令
[root@localhost ~]# type cd
cd is a shell builtin //cd是内嵌命令
二、命令行格式
在 Linux 操作系统中,凡是在字符操作界面中输入能够完成特定操作和任务的字符串都可以称为命令。严格来说,命令通常只代表实现某一类功能的程序的名称。
命令行格式:命令字 [选项] [参数]
命令字——是整条命令中最关键的一部分,需要安装在系统中,内部命令默认安装在系统里,开发者也安装了一些常用的外部命令。
选项——短格式选项:使用“-”符号引导 通常一个字母。长格式选项:使用“--”符号引导 通常完整的单词。
参数——命令字的处理对象可以是文件名、目录(路径)名或用户名等内容,个数可以是零到多个。
三、常用辅助操作
快捷键 | 功能 |
Tab 键 | 自动补齐(两次可以显示所有选项) |
反斜杠 \ | 强制换行或转义 |
Ctrl+l | 清屏 |
Ctrl+c | 强制停止执行命令 |
Ctrl+s/Ctrl+q | 锁屏/解锁 |
上下箭头 | 翻看执行过的命令 |
Ctrl+a | 光标移到最前 |
Ctrl+e 或 end | 光标移到最后 |
Ctrl+U | 清空至行首不包括当前光标处的字符 |
Ctrl+K | 清空至行尾包括当前光标处的字符 |
Ctrl+w | 从当前光标删除到开头 |
四、查看帮助命令
help 内部命令 //查看内部帮助命令
[root@localhost ~]# help echo
echo: echo [-neE] [arg ...]
Write arguments to the standard output.
Display the ARGs on the standard output followed by a newline.
Options:
-n do not append a newline
-e enable interpretation of the following backslash escapes
-E explicitly suppress interpretation of backslash escapes
`echo' interprets the following backslash-escaped characters:
\a alert (bell)
\b backspace
\c suppress further output
\e escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\0nnn the character whose ASCII code is NNN (octal). NNN can be
0 to 3 octal digits
\xHH the eight-bit character whose value is HH (hexadecimal). HH
can be one or two hex digits
Exit Status:
Returns success unless a write error occurs.
外部命令 --help //查看外部帮助命令
[root@localhost ~]# mkdir --help
Usage: mkdir [OPTION]... DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
-m, --mode=MODE set file mode (as in chmod), not a=rwx - umask
-p, --parents no error if existing, make parent directories as needed
-v, --verbose print a message for each created directory
-Z set SELinux security context of each created directory
to the default type
--context[=CTX] like -Z, or if CTX is specified then set the SELinux
or SMACK security context to CTX
--help display this help and exit
--version output version information and exit
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'mkdir invocation'
man [区段] 命令字 //查看manual帮助手册
有些指令或程序可能有一个以上的主题,它们位于不同的区段中。因此,要查看较后的区
段,你可以在此指定man查找区段的顺序(默认为1)。具体区段划分如下所示:
区段1:用户指令
区段2:系统调用
区段3:程序库调用
区段4:设备
区段5:文件格式
区段6:游戏
区段7:杂项
区段8:系统指令
区段9:内核内部指令
区段n:Tcl或Tk指令