温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Linux中的内置命令和外部命令

发布时间:2021-09-03 15:38:57 来源:亿速云 阅读:96 作者:chen 栏目:系统运维

本篇内容主要讲解“Linux中的内置命令和外部命令”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Linux中的内置命令和外部命令”吧!

Linux的命令分为内部命令和外部命令:

1.内部命令在系统启动时就调入内存,是常驻内存的,所以执行效率高。
2.外部命令是系统的软件功能,用户需要时才从硬盘中读入内存。

type可以用来判断一个命令是否为内置命令

代码如下:


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既可以查看内部命令,同时也可以判断是否为内部命令

代码如下:


[root@linuxeye ~]# enable -a #查看内部命令
[root@linuxeye ~]# enable whiptail #非内部命令
-bash: enable: whiptail: not a shell builtin
[root@linuxeye ~]# enable pwd #是内部命令

内部命令用户输入时系统调用的速率快,不是内置命令,系统将会读取环境变量文件.bash_profile、/etc/profile去找PATH路径。

然后在提一下命令的调用,有些历史命令使用过后,会存在在hash表中,当你再次输入该命令它的调用会是这样一个过程。

hash——>内置命令——>PATH   命令的调用其实应该是这样一个过程。

代码如下:


[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表不存放系统内置命令。

到此,相信大家对“Linux中的内置命令和外部命令”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI