大佬教程收集整理的这篇文章主要介绍了Linux shell 内部命令与外部命令有什么区别以及怎么辨别,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
外部命令是linux系统中的实用程序部分,因为实用程序的功能通常都比较强大,所以其包含的程序量也会很大,在系统加载时并不随系统一起被加载到内存中,而是在需要时才将其调用内存。通常外部命令的实体并不包含在sHell中,但是其命令执行过程是由sHell程序控制的。sHell程序管理外部命令执行的路径查找、加载存放,并控制命令的执行。外部命令是在bash之外额外安装的,通常放在/bin,/usr/bin,/sbin,/usr/sbin......等等。可通过“echo
内部命令和外部命令最大的区别之处就是性能。内部命令由于构建在sHell中而不必创建多余的进程,要比外部命令执行快得多。因此和执行更大的脚本道理一样,执行包含很多外部命令的脚本会损害脚本的性能。
1.内部命令在系统启动时就调入内存,是常驻内存的,所以执行效率高。
2.外部命令是系统的软件功能,用户需要时才从硬盘中读入内存。
type可以用来判断一个命令是否为内置命令
type: usage: type [-afptP] name [name ...]
[[email protected] ~]# type type type is a sHell builTin [[email protected] ~]# type -p type [[email protected] ~]# type -t type builTin [[email protected] ~]# type type type is a sHell builTin [[email protected] ~]# type -t type builTin [[email protected] ~]# type pwd pwd is a sHell builTin [[email protected] ~]# type whiptail whiptail is /usr/bin/whiptail [[email protected] ~]# type -t whiptail file
enable既可以查看内部命令,同时也可以判断是否为内部命令
[[email protected] ~]# enable -a #查看内部命令 [[email protected] ~]# enable whiptail #非内部命令 -bash: enable: whiptail: not a sHell builTin [[email protected] ~]# enable pwd #是内部命令
内部命令用户输入时系统调用的速率快,不是内置命令,系统将会读取环境变量文件.bash_profile、/etc/profile去找PATH路径。
然后在提一下命令的调用,有些历史命令使用过后,会存在在hash表中,当你再次输入该命令它的调用会是这样一个过程。
hash——>内置命令——>PATH 命令的调用其实应该是这样一个过程。
[[email protected] ~]# type pwd pwd is a sHell builTin [[email protected] ~]# type cat cat is /usr/bin/cat [[email protected] ~]# pwd /root [[email protected] ~]# ls linuxeye* linuxeye.pem linuxeye.txt [[email protected] ~]# cat linuxeye.txt linuxeye [[email protected] ~]# hash -l #显示hash表 builTin hash -p /usr/bin/cat cat builTin hash -p /usr/bin/ls ls [[email protected] ~]# type cat cat is hashed (/usr/bin/cat) [[email protected] ~]# hash -r #清除hash表 [[email protected] ~]# type cat cat is /usr/bin/cat
从上面操作@R_450_10333@。hash表不存放系统内置命令。
以上是大佬教程为你收集整理的Linux shell 内部命令与外部命令有什么区别以及怎么辨别全部内容,希望文章能够帮你解决Linux shell 内部命令与外部命令有什么区别以及怎么辨别所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。