- 使用命令
- 命令的存放形式
- 是一个可执行文件,它们位于/usr/bin下下,比如用C或者C++编写的程序或者用脚本语言编写的脚本程序,比如shell,perl,python等等
- 是一个内置的shell自身命令,比如 cd 命令
- 是一个shell函数,常用于环境变量中,后续章节会介绍
- 是一个命令别名,建立在内置命令之上
- type – 说明怎样解释一个命令名
- 概念:用于说明某个命令属于以上四种命令形式中的哪一种
- 语法:type common
- 举例:
- 可执行程序
[root@zabbix ~]# type nexus
nexus is /usr/bin/nexus
- 内置shell
[root@zabbix ~]# type cd
cd is a shell builtin
- 命令别名
[root@zabbix ~]# type cp
cp is aliased to `cp -i'
- 可执行程序
- which – 显示会执行程序在哪里
-
[root@zabbix ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls
[root@zabbix ~]# which cd
/usr/bin/cd
[root@zabbix ~]# which nexus
/usr/bin/nexus
[root@zabbix ~]# which cp
alias cp='cp -i'
/usr/bin/cp
[root@zabbix ~]#
-
- help -- 帮助选项
- 作用:显示帮助说明
- 帮助内容两种显示形式:一个命令一般只支持一种显示形式
- help在前面:
- 语法:help common
- 举例:
[root@zabbix ~]# help cd
cd: cd [-L|[-P [-e]]] [dir] [ ]表示可选选项,| 表示互斥选项,也就是要么-L,要么-P,两种不能同时出现
Change the shell working directory.
Options:
-L force symbolic links to be followed
-P use the physical directory structure without following symbolic
links
-e if the -P option is supplied, and the current working directory
cannot be determined successfully, exit with a non-zero status
- help在后面:
- 语法: common --help
- 举例:
[root@zabbix ~]# cd --help
-bash: cd: --: invalid option 说明cd 命令不支持后置help,只支持前置help
cd: usage: cd [-L|[-P [-e]]] [dir]
[root@zabbix ~]# mkdir –help 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
- help在前面:
- 举例:
- man – 显示命令手册页
- 作用:以分页的形式显示命令内容
- 语法:man common
- 举例:翻页操作参照: 第4章:研究操作系统 中的less命令
[root@zabbix ~]# man cd
is searched if no file is found in PATH. If the sourcepath option to the
shopt builtin command is turned off, the PATH is not searched. If any
arguments are supplied, they become the positional parameters when file‐
name is executed. Otherwise the positional parameters are unchanged.
Manual page cd(1) line 1/1489 2% (press h for help or q to quit) 1/1489:1表示当前页 1489表示总的页手
- man手册章节安排
章节 内容 1 用户命令 2 程序接口内核系统调用 3 C 库函数程序接口 4 特殊文件,比如说设备结点和驱动程序 5 文件格式 6 游戏娱乐,如屏幕保护程序 7 其他方面 8 系统管理员命令 - 通过段代号定位章节,通常默认是第1段
- apropos – 显示一系列适合的命令
- 作用:按关键字查找手册页
- 举例:
[root@zabbix wys_bak]# apropos reset
clearerr (3) - check and reset stream status
feof (3) - check and reset stream status
ferror (3) - check and reset stream status
fileno (3) - check and reset stream status
- 按章节和手册页打开手册
[root@zabbix wys_bak]# man 3 fileno
clearerr, feof, ferror, fileno - check and reset stream status
- whatis– 显示一个命令的简洁描述
- 作用:显示非常简短的命令说明
-
[root@zabbix wys_bak]# whatis mkdir
mkdir (1) - make directories
mkdir (1p) - make directories
mkdir (2) - create a directory
mkdir (3p) - make a directory
- 举例:
[root@zabbix wys_bak]# man 3 fileno
clearerr, feof, ferror, fileno - check and reset stream status
- info – 显示命令 info,是命令手册的替代物
- alias – 创建命令别名
- 作用:将多个命令也就是组合命令拼接到一个命令中
- 查看系统预先定义的别名
[root@zabbix wys_bak]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i' 默认提示原来在这里设置了
alias rm='rm -i' 默认提示原来在这里设置了
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
- 语法:alias 别名='命令组合',命令组合中多个命令之间用分号隔开
- 举例:
[root@zabbix wys_bak]# alias nexus_home='cd /home/nexus;ls;cd -' 定义别名
[root@zabbix wys_bak]# nexus_home 使用命令别名
nexus nexus-2.14.9-01 sonatype-work
/root/wys_bak
[root@zabbix wys_bak]#
- 别名注意事项
- 定义好别名后可以在当前窗口的任何目录执行
- 如果当前窗口关闭后该命令别名就会失效,后续会介绍如何保持窗口永生效
- 删除别名
[root@zabbix wys_bak]# unalias nexus_home
[root@zabbix wys_bak]# nexus_home
-bash: nexus_home: command not found