知识梳理,回顾之前所学习的一些命令语法。
# tty命令:显示当前终端对应终端设备文件
[root@VM_168_102_centos ~]# tty /dev/pts/0
如何识别哪种终端:
/dev/ttyS#:串行终端
/dev/centsole:物理终端
/dev/tty#:虚拟终端
/dev/pts/#:伪终端
#who命令:查看当前系统上登录的所有用户及其信息
[root@VM_168_102_centos ~]# who root pts/0 Aug 3 11:26 (222.36.73.57) wanghan pts/1 Aug 3 11:54 (222.36.73.57)
用who命令也可以查看当前终端对应终端设备文件
# basename命令和dirname命令区别:
basenmae:取路径基名
[root@VM_168_102_centos ~]# basename /etc/passwd/wanghan/ceshi ceshi [root@VM_168_102_centos ~]# basename /etc/passwd/wanghan/ wanghan [root@VM_168_102_centos ~]# basename /etc/passwd passwd [root@VM_168_102_centos ~]# basename /etc etc
dirname:取路径目录名
[root@VM_168_102_centos ~]# dirname /etc/passwd/wanghan/ceshi /etc/passwd/wanghan [root@VM_168_102_centos ~]# dirname /etc/passwd/wanghan/ /etc/passwd [root@VM_168_102_centos ~]# dirname /etc/passwd/ /etc
#type命令:查看当前命令是哪种类型(内建命令或外部命令)
[root@VM_168_102_centos ~]# type cd cd is a shell builtin
builtin:在shell程序中实现的命令即为内建命令
[root@VM_168_102_centos ~]# type cat cat is /bin/cat
外部命令:在文件系统上的某位置有一个与命令名称对应的可执行文件
#hash命令:查看hash查找表中执行过的与命令名称相对应的可执行文件
[root@VM_168_102_centos ~]# hash hits command 2 /usr/bin/tty 7 /bin/basename 5 /usr/bin/tail 3 /usr/bin/dirname 2 /usr/sbin/useradd 4 /usr/bin/who 1 /usr/bin/man 1 /usr/bin/passwd 1 /usr/bin/id 3 /bin/ls 9 /usr/sbin/usermod 3 /bin/su 3 /usr/bin/clear
hash �Cr 清空表
[root@VM_168_102_centos ~]# hash -r [root@VM_168_102_centos ~]# hash hash: hash table empty
#which命令:which命令的作用是,在PATH变量指定的路径中,搜索某个系统命令的位置,并且返回第一个搜索结果。也就是说,使用which命令,就可以看到某个系统命令是否存在,以及执行的到底是哪一个位置的命令。
[root@VM_168_102_centos ~]# which cat /bin/cat [root@VM_168_102_centos ~]# which passwd /usr/bin/passwd
注意:
[root@VM_168_102_centos ~]# which cd /usr/bin/which: no cd in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin) [root@VM_168_102_centos ~]# type cd cd is a shell builtin
cd是内建命令,所以which通过PATH变量中指定的路径是搜索不到的。
#如何获取命令帮助:
内建命令帮助获取:hlep命令
首先确定命令类型
[root@VM_168_102_centos ~]# help cd cd: cd [-L|-P] [dir] Change the shell working directory. Change the current directory to DIR. The default DIR is the value of the HOME shell variable. The variable CDPATH defines the search path for the directory containing DIR. Alternative directory names in CDPATH are separated by a colon (:). A null directory name is the same as the current directory. If DIR begins with a slash (/), then CDPATH is not used. If the directory is not found, and the shell option `cdable_vars' is set, the word is assumed to be a variable name. If that variable has a value, its value is used for DIR. Options: -L force symbolic links to be followed -P use the physical directory structure without following symbolic links The default is to follow symbolic links, as if `-L' were specified. Exit Status: Returns 0 if the directory is changed; non-zero otherwise.
注意:如果输入外部命令
[root@VM_168_102_centos ~]# help cat -bash: help: no help topics match `cat'. Try `help help' or `man -k cat' or `info cat'.
找不到相关帮助,并提示你去man中查找
外部命令帮助获取:--hlep(使用的是manual)
[root@VM_168_102_centos ~]# cat --help Usage: cat [OPTION]... [FILE]... Concatenate FILE(s), or standard input, to standard output. -A, --show-all equivalent to -vET -b, --number-nonblank number nonempty output lines -e equivalent to -vE -E, --show-ends display $ at end of each line -n, --number number all output lines -s, --squeeze-blank suppress repeated empty output lines -t equivalent to -vT -T, --show-tabs display TAB characters as ^I -u (ignored) -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB --help display this help and exit --version output version information and exit With no FILE, or when FILE is -, read standard input. Examples: cat f - g Output f's contents, then standard input, then g's contents. cat Copy standard input to standard output. Report cat bugs to [email protected] GNU coreutils home page: <http://www.gnu.org/software/coreutils/> General help using GNU software: <http://www.gnu.org/gethelp/> Report cat translation bugs to <http://translationproject.org/team/> For complete documentation, run: info coreutils 'cat invocation'
注意:如果输入内部命令
[root@VM_168_102_centos ~]# cd --help -bash: cd: --: invalid option cd: usage: cd [-L|-P] [dir] [root@VM_168_102_centos ~]# type --help -bash: type: --: invalid option type: usage: type [-afptP] name [name ...]
会提示当前输入命令(cd/type)后面跟着的选项(--help)不存在,并提示你当前输入的命令(cd/type)的用法。
通过man手册获取命令帮助:man命令
#man 命令
可以通过 man builtin(man 任意内建命令均可) 查看所有内建命令相关帮助
BASH_BUILTINS(1) BASH_BUILTINS(1) NAME bash, :, ., [, alias, bg, bind, break, builtin, caller, cd, command, compgen, complete, compopt, continue, declare, dirs, disown, echo, enable, eval, exec, exit, export, false, fc, fg, getopts, hash, help, history, jobs, kill, let, local, logout, mapfile, popd, printf, pushd, pwd, read, readonly, return, set, shift, shopt, source, suspend, test, times, trap, true, type, typeset, ulimit, umask, unalias, unset, wait - bash built-in commands, see bash(1)
可以结合man手册中检索命令进行具体相关命令查询
man手册中操作:
空格键:向尾部翻一屏
B键:向首部翻一屏
回车键:向尾部翻一行
K键:向首部翻一行
CTRL+D:向尾部翻半屏
CTRL+U:向首部翻半屏
/keyword:像尾部搜索当前输入关键词
?keyword:像首部搜索当前输入关键词
搜索出相关关键词后可以通过“n/N”键进行关键词之间上下跳转
q键:退出
如何在命令帮助中查找关键字相关信息:
#whatis命令:可以通过在命令帮助中搜索出当前输入命令的相关信息(精确查找),告知命令主要用途。
#man �Ck命令:可以通过在命令帮助中搜索出当前输入命令的相关信息(模糊查找)