日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

对”命令“操作的命令

發(fā)布時間:2023/12/10 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 对”命令“操作的命令 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.


????乍一看這個標題有點拗口,什么叫對“命令”操作的命令呢?其實從字面上就可以理解我要表達的意思,今天這篇博客寫的還是命令,但是這些命令有點不一樣,不一樣的地方在于這些命令操作的對象就是“命令”。


1,? type,type可以查看命令是屬于shell的內(nèi)建命令還是外部命令

[root@node1?~]#?type?cd cd?is?a?shell?builtin [root@node1?~]#?type?ls ls?is?aliased?to?`ls?--color=auto' [root@node1?~]#?type?cd cd?is?a?shell?builtin [root@node1?~]#?type?vi vi?is?/bin/vi

type后可以跟-a選項

[root@node1?/]#?type?-a?pwd pwd?is?a?shell?builtin pwd?is?/bin/pwd


2,? whereis,在linux中一切皆文件,命令也不例外,whereis就可以幫你定位這些“命令”文件的為位置和幫助文檔

[root@node1~]#?whereis?vi vi:/bin/vi?/usr/share/man/man1/vi.1.gz?/usr/share/man/man1p/vi.1p.gz [root@node1~]#?whereis?cd cd:/usr/share/man/man1/cd.1.gz?/usr/share/man/man1p/cd.1p.gz [root@node1~]#?whereis?ls ls:?/bin/ls/usr/share/man/man1/ls.1.gz?/usr/share/man/man1p/ls.1p.gz


3,? which,which的原意是哪一個,而linux中which可以列出命令的別名,命令的位置,以及命令相關(guān)的man文檔的位置

root@node1?~]#?which?ls alias?ls='ls?--color=auto' /bin/ls [root@node1?~]#?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) [root@node1?~]#?which?vi /bin/vi [root@node1?~]#?whereis?vi vi:?/bin/vi?/usr/share/man/man1/vi.1.gz/usr/share/man/man1p/vi.1p.gz


4,? alias,給命令制定一個別名,用戶可以通過alias對命令做一些貼近個人習慣的定制

[root@node1~]#?alias?la='ls?-al' [root@node1~]#?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

取消別名

[root@node1~]#?unalias?la [root@node1~]#?la -bash:la:?command?not?found

alias對命令設(shè)置別名之后僅僅在當前shell中生效,如果想保存這一設(shè)定的話,就必須將其保存在配置文件中

[root@node1~]#?echo?"?alias?la='ls?-al'"?>>?/etc/bashrc

此操作會對全局生效,如果僅僅相對某個用戶生效可以

[root@node1~]#?echo?"?alias?la='ls?-al'"?>>?~/.bashrc


4,whatis,有了whereis which,有沒有whatwhywhen呢,答案是沒有,但是有個whatis,而且這個whatis可能和你們想的不一樣

[root@node1?~]#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這九個章節(jié)中的哪個章節(jié)的

[root@node1?~]#?whatis?passwd passwd???????????????(1)??-?update?user's?authentication?tokens passwd???????????????(5)??-?password?file passwd?[sslpasswd]??(1ssl)??-?compute?password?hashes

有的時候你可能會遇到這樣的情況

[root@node1?~]#?whatis?passwd passwd:?nothing?appropriate

你只需要makewhatis一下就可以了

[root@node1?~]#?makewhatis

?

? ? 最后再說一說命令的搜索路徑,大家都知道當在shell中輸入命令之后,shell就會在文件系統(tǒng)中尋找這個命令對應(yīng)的文件,而對于這個尋找的路徑大家應(yīng)該也很熟悉了,就是$PATH這一環(huán)境變量

[root@node1?~]#?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真正的搜索路徑應(yīng)該是

1,? alias

2,? hashtable

3,? function

4,? builtins

5,? $PATH


1. alias,如果用戶定義了別名的話,那么別名會先被搜索到并且執(zhí)行,不論是別名是否被保存至配置文件都是如此

[root@node1?~]#?alias?la='ls?-al' [root@node1?~]#?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-distri


2. hashtable

[root@node1?~]#?hash hits??command1?????????/bin/date1?????????/usr/bin/vim1?????????/bin/ls

hashtable其實是用戶在執(zhí)行命令之后shell將搜索的結(jié)果的緩存,這樣可以提高搜索的效率和速度,但是hash是不會記錄shell的內(nèi)部命令,functions以及定義路徑的別名的

那什么叫定義了路徑的別名呢

[root@node1?~]#?hash?-r [root@node1?~]#?hash hash:?hash?table?empty

清空hash

[root@node1?~]#?alias?ls='ls' [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 [root@node1?~]#?hash hits??command1?????????/bin/ls [root@node1?~]#?unalias?ls [root@node1?~]#?hash hits??command 1?????????????/bin/ls

為ls指定了沒有指定路徑的別名后,hash結(jié)果為1

[root@node1?~]#?alias?ls='/bin/ls' [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 [root@node1?~]#?hash hits??command 1?????????????/bin/ls

在取消了第一次別名之后再為ls指定一個指定了路徑的別名之后,hash結(jié)果仍然為一并未發(fā)生變化,證明這一次指定路徑的別名并沒有被緩存只hashtable

[root@node1?~]#?unalias?ls [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 [root@node1?~]#?hash hits??command2?????????/bin/ls [root@node1?~]#

取消別名再執(zhí)行l(wèi)s之后,hashtable中變?yōu)?/span>2


3,function

function指的是一些用戶自定義的函數(shù),且此函數(shù)名和shell的命令名稱相同,此時shell會優(yōu)先執(zhí)行用戶自定義的函數(shù)

[root@node1?~]#?function?cd?{?echo"just?for?a?test";} [root@node1?~]#?cd just?for?a?test

在用戶自定了cd這函數(shù)之后再輸入cd就是執(zhí)行剛才用戶定義的函數(shù)而不是shell命令cd

要是想執(zhí)行原本在shellcd命令改怎么辦呢只需要在cd前加上builtin就可以

[root@node1?~]#?builtin?cd?/ [root@node1?/]#

type -a cd可以看到以下結(jié)果

[root@node1?/]#?type?-a?cd cd?is?a?function cd?() {echo?"just?for?a?test" } cd?is?a?shell?builtin

cd不僅是一個shell內(nèi)建的命令,而且是用戶定義的函數(shù)


4,builtins,接下來是檢索的是shell的內(nèi)建的命令


5,? 最后才是$PATH中定義的搜索路徑

[root@node1?/]#?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


轉(zhuǎn)載于:https://blog.51cto.com/viperstars/1423293

總結(jié)

以上是生活随笔為你收集整理的对”命令“操作的命令的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。