廊坊网站制作官网,百度提交网址多久才会收录,wordpress 建站教程,天猫淘宝旗舰店乍一看这个标题有点拗口#xff0c;什么叫对“命令”操作的命令呢#xff1f;其实从字面上就可以理解我要表达的意思#xff0c;今天这篇博客写的还是命令#xff0c;但是这些命令有点不一样#xff0c;不一样的地方在于这些命令操作的对象就是“命令”。1#xff0c; t… 乍一看这个标题有点拗口什么叫对“命令”操作的命令呢其实从字面上就可以理解我要表达的意思今天这篇博客写的还是命令但是这些命令有点不一样不一样的地方在于这些命令操作的对象就是“命令”。1 typetype可以查看命令是属于shell的内建命令还是外部命令[rootnode1 ~]# type cd
cd is a shell builtin
[rootnode1 ~]# type ls
ls is aliased to ls --colorauto
[rootnode1 ~]# type cd
cd is a shell builtin
[rootnode1 ~]# type vi
vi is /bin/vitype后可以跟-a选项[rootnode1 /]# type -a pwd
pwd is a shell builtin
pwd is /bin/pwd2 whereis在linux中一切皆文件命令也不例外whereis就可以帮你定位这些“命令”文件的为位置和帮助文档[rootnode1~]# whereis vi
vi:/bin/vi /usr/share/man/man1/vi.1.gz /usr/share/man/man1p/vi.1p.gz
[rootnode1~]# whereis cd
cd:/usr/share/man/man1/cd.1.gz /usr/share/man/man1p/cd.1p.gz
[rootnode1~]# whereis ls
ls: /bin/ls/usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz3 whichwhich的原意是哪一个而linux中which可以列出命令的别名命令的位置以及命令相关的man文档的位置rootnode1 ~]# which ls
alias lsls --colorauto
/bin/ls
[rootnode1 ~]# which cd
/usr/bin/which: no cd in(/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[rootnode1 ~]# which vi
/bin/vi
[rootnode1 ~]# whereis vi
vi: /bin/vi /usr/share/man/man1/vi.1.gz/usr/share/man/man1p/vi.1p.gz4 alias给命令制定一个别名用户可以通过alias对命令做一些贴近个人习惯的定制[rootnode1~]# alias lals -al
[rootnode1~]# la
total59428
dr-xr-x---.22 root root 4096 Jun 6 14:15 .
dr-xr-xr-x.25 root root 4096 Jun 7 08:34 ..
drwxr-xr-x. 2 root root 4096 May 6 08:44 .abrt
-rw-------. 1 root root 1592 May 7 04:40 anaconda-ks.cfg
-rw-------. 1 root root 534 Jun 6 14:16 .bash_history
-rw-r--r--. 1 root root 18 May 20 2009 .bash_logout
-rw-r--r--. 1 root root 176 May 20 2009 .bash_profile
-rw-r--r--. 1 root root 176 Sep 23 2004 .bashrc
drwxr-xr-x. 2 root root 4096 May 6 08:46 .cache
drwx------. 4 root root 4096 May 6 08:44 .config
-rw-r--r--. 1 root root 100 Sep 23 2004 .cshrc
drwx------. 3 root root 4096 May 6 08:44 .dbus
drwxr-xr-x. 2 root root 4096 May 6 08:44 Desktop
drwxr-xr-x. 2 root root 4096 May 6 08:44 Documents
drwxr-xr-x. 2 root root 4096 May 6 08:44 Downloads
-rw-------. 1 root root 16 May 6 08:44 .esd_auth
drwx------. 4 root root 4096 May 6 20:53 .gconf
drwx------. 2 root root 4096 May 6 20:55 .gconfd
drwx------. 5 root root 4096 May 6 08:44 .gnome2
-rw-r--r--. 1 root root 107 May 6 20:53 .gtk-bookmarks
drwx------. 2 root root 4096 May 6 08:44 .gvfs
-rw-------. 1 root root 620 May 6 20:53 .ICEauthority
-rw-r--r--. 1 root root 623 May 6 20:53 .imsettings.log
-rw-r--r--. 1 root root 48228 May 7 04:40 install.log
-rw-r--r--. 1 root root 9360 May 7 04:37 install.log.syslog
drwxr-xr-x. 3 root root 4096 May 6 08:44 .local
drwxr-xr-x. 2 root root 4096 May 6 08:44 Music
drwxr-xr-x. 2 root root 4096 May 6 08:44 .nautilus
drwxr-xr-x. 2 root root 4096 May 6 08:44 Pictures
drwxr-xr-x. 2 root root 4096 May 6 08:44 Public
drwx------. 2 root root 4096 May 6 08:44 .pulse
-rw-------. 1 root root 256 May 6 08:44 .pulse-cookie
-rw-------. 1 root root 218 May 6 20:55 .recently-used.xbel
-rw-r--r--. 1 root root 129 Dec 4 2004 .tcshrc
drwxr-xr-x. 2 root root 4096 May 6 08:44 Templates
drwxr-xr-x. 2 root root 4096 May 6 08:44 Videos
-rw-------. 1 root root 3992 Jun 6 14:15 .viminfo
-r--r--r--. 1 root root 60638465 May 6 08:46 VMwareTools-9.6.1-1378637.tar.gz
drwxr-xr-x. 7 root root 4096 Oct 18 2013 vmware-tools-distrib取消别名[rootnode1~]# unalias la
[rootnode1~]# la
-bash:la: command not foundalias对命令设置别名之后仅仅在当前shell中生效如果想保存这一设定的话就必须将其保存在配置文件中[rootnode1~]# echo alias lals -al /etc/bashrc此操作会对全局生效如果仅仅相对某个用户生效可以[rootnode1~]# echo alias lals -al ~/.bashrc4whatis有了whereis 和which有没有whatwhywhen呢答案是没有但是有个whatis而且这个whatis可能和你们想的不一样[rootnode1 ~]#whatis cd
cd (1p) - change the working directory
cd [builtins] (1) - bash built-in commands, see bash(1)
cd-drive (1) - manual page for cd-drive
cd-info (1) - manual page for cd-info
cd-paranoia 9.8 (Paranoia release III via libcdio) [cd-paranoia](1) - an audio CD reading utility whichincludes extra data verification features
cd-read (1) - manual page for cd-read version 0.81原来这个是查看这个命令在man文档中1-9这九个章节中的哪个章节的[rootnode1 ~]# whatis passwd
passwd (1) - update users authentication tokens
passwd (5) - password file
passwd [sslpasswd] (1ssl) - compute password hashes有的时候你可能会遇到这样的情况[rootnode1 ~]# whatis passwd
passwd: nothing appropriate你只需要makewhatis一下就可以了[rootnode1 ~]# makewhatis 最后再说一说命令的搜索路径大家都知道当在shell中输入命令之后shell就会在文件系统中寻找这个命令对应的文件而对于这个寻找的路径大家应该也很熟悉了就是$PATH这一环境变量[rootnode1 ~]# echo $PATH
/usr/lib64/qt3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin 但是实际上shell在搜索$PATH之前会先去别的地方搜索而$PATH其实是最后搜索的地方shell真正的搜索路径应该是1 alias2 hashtable3 function4 builtins5 $PATH1. alias如果用户定义了别名的话那么别名会先被搜索到并且执行不论是别名是否被保存至配置文件都是如此[rootnode1 ~]# alias lals -al
[rootnode1 ~]# la
total 59428
dr-xr-x---. 22 root root 4096 Jun 6 14:15 .
dr-xr-xr-x. 25 root root 4096 Jun 7 08:34 ..
drwxr-xr-x. 2 root root 4096 May 6 08:44 .abrt
-rw-------. 1 root root 1592 May 7 04:40 anaconda-ks.cfg
-rw-------. 1 root root 534 Jun 6 14:16 .bash_history
-rw-r--r--. 1 root root 18 May 20 2009 .bash_logout
-rw-r--r--. 1 root root 176 May 20 2009 .bash_profile
-rw-r--r--. 1 root root 176 Sep 23 2004 .bashrc
drwxr-xr-x. 2 root root 4096 May 6 08:46 .cache
drwx------. 4 root root 4096 May 6 08:44 .config
-rw-r--r--. 1 root root 100 Sep 23 2004 .cshrc
drwx------. 3 root root 4096 May 6 08:44 .dbus
drwxr-xr-x. 2 root root 4096 May 6 08:44 Desktop
drwxr-xr-x. 2 root root 4096 May 6 08:44 Documents
drwxr-xr-x. 2 root root 4096 May 6 08:44 Downloads
-rw-------. 1 root root 16 May 6 08:44 .esd_auth
drwx------. 4 root root 4096 May 6 20:53 .gconf
drwx------. 2 root root 4096 May 6 20:55 .gconfd
drwx------. 5 root root 4096 May 6 08:44 .gnome2
-rw-r--r--. 1 root root 107 May 6 20:53 .gtk-bookmarks
drwx------. 2 root root 4096 May 6 08:44 .gvfs
-rw-------. 1 root root 620 May 6 20:53 .ICEauthority
-rw-r--r--. 1 root root 623 May 6 20:53 .imsettings.log
-rw-r--r--. 1 root root 48228 May 7 04:40 install.log
-rw-r--r--. 1 root root 9360 May 7 04:37 install.log.syslog
drwxr-xr-x. 3 root root 4096 May 6 08:44 .local
drwxr-xr-x. 2 root root 4096 May 6 08:44 Music
drwxr-xr-x. 2 root root 4096 May 6 08:44 .nautilus
drwxr-xr-x. 2 root root 4096 May 6 08:44 Pictures
drwxr-xr-x. 2 root root 4096 May 6 08:44 Public
drwx------. 2 root root 4096 May 6 08:44 .pulse
-rw-------. 1 root root 256 May 6 08:44 .pulse-cookie
-rw-------. 1 root root 218 May 6 20:55 .recently-used.xbel
-rw-r--r--. 1 root root 129 Dec 4 2004 .tcshrc
drwxr-xr-x. 2 root root 4096 May 6 08:44 Templates
drwxr-xr-x. 2 root root 4096 May 6 08:44 Videos
-rw-------. 1 root root 3992 Jun 6 14:15 .viminfo
-r--r--r--. 1 root root60638465 May 6 08:46VMwareTools-9.6.1-1378637.tar.gz
drwxr-xr-x. 7 root root 4096 Oct 18 2013 vmware-tools-distri2. hashtable[rootnode1 ~]# hash
hits command1 /bin/date1 /usr/bin/vim1 /bin/lshashtable其实是用户在执行命令之后shell将搜索的结果的缓存这样可以提高搜索的效率和速度但是hash是不会记录shell的内部命令functions以及定义路径的别名的那什么叫定义了路径的别名呢[rootnode1 ~]# hash -r
[rootnode1 ~]# hash
hash: hash table empty清空hash表[rootnode1 ~]# alias lsls
[root node1 ~]# ls
anaconda-ks.cfg Desktop Documents Downloads install.log install.log.syslog Music Pictures Public Templates Videos VMwareTools-9.6.1-1378637.tar.gz vmware-tools-distrib
[rootnode1 ~]# hash
hits command1 /bin/ls
[rootnode1 ~]# unalias ls
[rootnode1 ~]# hash
hits command
1 /bin/ls为ls指定了没有指定路径的别名后hash结果为1[rootnode1 ~]# alias ls/bin/ls
[rootnode1 ~]# ls
anaconda-ks.cfg Desktop Documents Downloads install.log install.log.syslog Music Pictures Public Templates Videos VMwareTools-9.6.1-1378637.tar.gz vmware-tools-distrib
[rootnode1 ~]# hash
hits command
1 /bin/ls在取消了第一次别名之后再为ls指定一个指定了路径的别名之后hash结果仍然为一并未发生变化证明这一次指定路径的别名并没有被缓存只hashtable中[rootnode1 ~]# unalias ls
[rootnode1 ~]# ls
anaconda-ks.cfg Desktop Documents Downloads install.log install.log.syslog Music Pictures Public Templates Videos VMwareTools-9.6.1-1378637.tar.gz vmware-tools-distrib
[rootnode1 ~]# hash
hits command2 /bin/ls
[rootnode1 ~]#取消别名再执行ls之后hashtable中变为23functionfunction指的是一些用户自定义的函数且此函数名和shell的命令名称相同此时shell会优先执行用户自定义的函数[rootnode1 ~]# function cd { echojust for a test;}
[rootnode1 ~]# cd
just for a test在用户自定了cd这函数之后再输入cd就是执行刚才用户定义的函数而不是shell命令cd了要是想执行原本在shell中cd命令改怎么办呢只需要在cd前加上builtin就可以[rootnode1 ~]# builtin cd /
[rootnode1 /]#type -a cd可以看到以下结果[rootnode1 /]# type -a cd
cd is a function
cd ()
{echo just for a test
}
cd is a shell builtincd不仅是一个shell内建的命令而且是用户定义的函数4builtins接下来是检索的是shell的内建的命令5 最后才是$PATH中定义的搜索路径[rootnode1 /]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin即以下几个路径/usr/lib64/qt-3.3/bin
/usr/local/sbin
/usr/local/bin
/sbin:/bin
/usr/sbin
/usr/bin
/root/bin 转载于:https://blog.51cto.com/viperstars/1423293