Linux下内置命令和外部命令详解

Linux210阅读模式

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

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

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

  1. type: usage: type [-afptP] name [name ...]
  1. [root@linuxeye ~]# type type
  2. type is a shell builtin
  3. [root@linuxeye ~]# type -p type
  4. [root@linuxeye ~]# type -t type
  5. builtin
  6. [root@linuxeye ~]# type type
  7. type is a shell builtin
  8. [root@linuxeye ~]# type -t type
  9. builtin
  10. [root@linuxeye ~]# type pwd
  11. pwd is a shell builtin
  12. [root@linuxeye ~]# type whiptail
  13. whiptail is /usr/bin/whiptail
  14. [root@linuxeye ~]# type -t whiptail
  15. file

enable既可以查看内部命令,同时也可以判断是否为内部命令

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

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

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

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

  1. [root@linuxeye ~]# type pwd  
  2. pwd is a shell builtin  
  3. [root@linuxeye ~]# type cat  
  4. cat is /usr/bin/cat  
  5. [root@linuxeye ~]# pwd  
  6. /root  
  7. [root@linuxeye ~]# ls linuxeye*  
  8. linuxeye.pem  linuxeye.txt  
  9. [root@linuxeye ~]# cat linuxeye.txt  
  10. linuxeye  
  11. [root@linuxeye ~]# hash -l #显示hash表  
  12. builtin hash -p /usr/bin/cat cat  
  13. builtin hash -p /usr/bin/ls ls  
  14. [root@linuxeye ~]# type cat  
  15. cat is hashed (/usr/bin/cat)  
  16. [root@linuxeye ~]# hash -r #清除hash表  
  17. [root@linuxeye ~]# type cat  
  18. cat is /usr/bin/cat  

从上面操作可以看出。hash表不存放系统内置命令。

Wed May 13 12:03:53 CST 2015

 
  • 本文由 yeho 发表于 2015-05-13
  • 转载请务必保留本文链接:https://linuxeye.com/416.html
浅谈Linux内存管理机制 Linux

浅谈Linux内存管理机制

经常遇到一些刚接触Linux的新手会问内存占用怎么那么多? 在Linux中经常发现空闲内存很少,似乎所有的内存都被系统占用了,表面感觉是内存不够用了,其实不然。这是Linux内存管理的一个优秀特性,在...
Linux

tmux – Linux终端管理软件

tmux是一个优秀的终端复用软件,类似GNU Screen,但来自于OpenBSD,采用BSD授权。使用它最直观的好处就是,通过一个终端登录远程主机并运行tmux后,在其中可以开启多个控制台而无需再“...
    • whiptail的用法,楼主有没有介绍的,搜了一些,看的有点懵,楼主参考了哪些材料,我想学习借鉴一下。感谢楼主分享。

    匿名

    发表评论

    匿名网友
    确定

    取消

    拖动滑块以完成验证