溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Linux中的內(nèi)置命令和外部命令

發(fā)布時(shí)間:2021-09-03 15:38:57 來源:億速云 閱讀:109 作者:chen 欄目:系統(tǒng)運(yùn)維

本篇內(nèi)容主要講解“Linux中的內(nèi)置命令和外部命令”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“Linux中的內(nèi)置命令和外部命令”吧!

Linux的命令分為內(nèi)部命令和外部命令:

1.內(nèi)部命令在系統(tǒng)啟動(dòng)時(shí)就調(diào)入內(nèi)存,是常駐內(nèi)存的,所以執(zhí)行效率高。
2.外部命令是系統(tǒng)的軟件功能,用戶需要時(shí)才從硬盤中讀入內(nèi)存。

type可以用來判斷一個(gè)命令是否為內(nèi)置命令

代碼如下:


type: usage: type [-afptP] name [name ...]

代碼如下:


[root@linuxeye ~]# type type
type is a shell builtin
[root@linuxeye ~]# type -p type
[root@linuxeye ~]# type -t type
builtin
[root@linuxeye ~]# type type
type is a shell builtin
[root@linuxeye ~]# type -t type
builtin
[root@linuxeye ~]# type pwd
pwd is a shell builtin
[root@linuxeye ~]# type whiptail
whiptail is /usr/bin/whiptail
[root@linuxeye ~]# type -t whiptail
file

enable既可以查看內(nèi)部命令,同時(shí)也可以判斷是否為內(nèi)部命令

代碼如下:


[root@linuxeye ~]# enable -a #查看內(nèi)部命令
[root@linuxeye ~]# enable whiptail #非內(nèi)部命令
-bash: enable: whiptail: not a shell builtin
[root@linuxeye ~]# enable pwd #是內(nèi)部命令

內(nèi)部命令用戶輸入時(shí)系統(tǒng)調(diào)用的速率快,不是內(nèi)置命令,系統(tǒng)將會讀取環(huán)境變量文件.bash_profile、/etc/profile去找PATH路徑。

然后在提一下命令的調(diào)用,有些歷史命令使用過后,會存在在hash表中,當(dāng)你再次輸入該命令它的調(diào)用會是這樣一個(gè)過程。

hash——>內(nèi)置命令——>PATH   命令的調(diào)用其實(shí)應(yīng)該是這樣一個(gè)過程。

代碼如下:


[root@linuxeye ~]# type pwd
pwd is a shell builtin
[root@linuxeye ~]# type cat
cat is /usr/bin/cat
[root@linuxeye ~]# pwd
/root
[root@linuxeye ~]# ls linuxeye*
linuxeye.pem  linuxeye.txt
[root@linuxeye ~]# cat linuxeye.txt
linuxeye
[root@linuxeye ~]# hash -l #顯示hash表
builtin hash -p /usr/bin/cat cat
builtin hash -p /usr/bin/ls ls
[root@linuxeye ~]# type cat
cat is hashed (/usr/bin/cat)
[root@linuxeye ~]# hash -r #清除hash表
[root@linuxeye ~]# type cat
cat is /usr/bin/cat

從上面操作可以看出。hash表不存放系統(tǒng)內(nèi)置命令。

到此,相信大家對“Linux中的內(nèi)置命令和外部命令”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI