命令可以是下面四种形式之一:
Linux命令行
[root@senlong playground]# type type
type is a shell builtin
[root@senlong playground]# type ls
ls is aliased to 'ls --color=auto'
[root@senlong playground]# type cp
cp is aliased to 'cp -i'
[me@linuxbox ~]$ which ls
/bin/ls
这个命令只对可执行程序有效,不包括内部命令和命令别名
man program
帮助文档的结构
章节 | 内容 |
---|---|
1 | 用户命令 |
2 | 程序接口内核系统调用 |
3 | C 库函数程序接口 |
4 | 特殊文件,比如说设备结点和驱动程序 |
5 | 文件格式 |
6 | 游戏娱乐,如屏幕保护程序 |
7 | 其他方面 |
8 | 系统管理员命令 |
[me@linuxbox ~]$ cd /usr; ls; cd -
bin games kerberos lib64 local share tmp
...
[me@linuxbox ~]$
在一行上联合了三个命令:
首先更改目录到/usr,然后列出目录内容,最后回到原始目录(用命令”cd ~”),结束在开始的地方。
现在,通过 alia 命令 把这一串命令转变为一个命令。
我们要做的第一件事就是为我们的新命令构想一个名字。
比方说”test”。在使用”test”之前,先用type命令查看其是否已经在命令中:
[me@linuxbox ~]$ type test
test is a shell builtin
test”名字已经被使用了。试一下”foo”:
[me@linuxbox ~]$ type foo
bash: type: foo: not found
”foo”还没被占用。创建命令别名:
[me@linuxbox ~]$ alias foo='cd /usr; ls; cd -'
注意命令结构:
alias name='string'
在命令”alias”之后,输入“name”,紧接着(没有空格)是一个等号,等号之后是 一串用引号引起的字符串,字符串的内容要赋值给 name。我们定义了别名之后, 这个命令别名可以使用在任何地方:
[me@linuxbox ~]$ foo
bin games kerberos lib64 local share tmp
...
[me@linuxbox ~]$
我们也可以使用 type 命令来查看我们的别名:
[me@linuxbox ~]$ type foo
foo is aliased to \`cd /usr; ls ; cd -\'
删除别名,使用 unalias 命令,像这样:
[me@linuxbox ~]$ unalias foo
[me@linuxbox ~]$ type foo
bash: type: foo: not found
查看系统中的所有别名:
[me@linuxbox ~]$ alias
alias l.='ls -d .* --color=tty'
...