linux内置命令多少个,Linux中的内置命令和外部命令详解

本文介绍了Linux系统中命令的两种类型:内部命令和外部命令,并提供了如何区分它们的方法。内部命令作为shell的一部分常驻内存,执行效率更高;而外部命令则在需要时从磁盘加载。文章还详细说明了使用type和enable命令来判断命令类型的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值