首页 > 其他 > 详细

第十七章 文件的执行过程

时间:2020-07-16 22:51:29      阅读:42      评论:0      收藏:0      [点我收藏+]


1. 系统会判断你输入的命令是否绝对路径,是直接执行

2. 如果是相对路径,系统会判断命令是否存在别名,如果存在,执行别名

3. 如果命令不存在别名,系统会判断输入的命令是否内置命令,如果是,直接执行

4. 如果不是内置命令,系统会查询内存的hash缓存表,如果命令存在缓存,则按照缓存执行

5. 如果hash缓存表中没有命令的缓存,系统会从环境变量PATH中的命令路径查询命令的路径进行执行

6. 如果PATH变量没有命令的路径,就会报错 command not found


#查询命令是否为内置命令

[root@jindada ~]# type -a cd
cd is a shell builtin
cd is /usr/bin/cd
[root@jindada ~]# type -a ls
ls is aliased to `ls --color=auto‘
ls is /usr/bin/ls

#查看系统中所有的内置命令

[root@jindada ~]# help


#查看当前窗口下所有外部命令的缓存表

[root@jindada ~]# hash
hits command
53 /usr/bin/grep
1 /usr/bin/egrep
1 /usr/bin/tail
6 /usr/bin/file

 


[root@jindada ~]# /usr/bin/wc /etc/hosts
2 10 158 /etc/hosts
[root@jindada ~]# ll /usr/bin/wc
-rwxr-xr-x. 1 root root 41688 Oct 31 2018 /usr/bin/wc
[root@jindada ~]# mv /usr/bin/wc /usr/bin/gl
[root@jindada ~]# wc /etc/hosts
-bash: /usr/bin/wc: No such file or directory
[root@jindada ~]# gl /etc/hosts
2 10 158 /etc/hosts
[root@jindada ~]# hash
hits command
53 /usr/bin/grep
1 /usr/bin/egrep
1 /usr/bin/tail
1 /usr/bin/gl


#从缓存中删除一个命令的缓存

[root@jindada ~]# hash -d wc


[root@jindada ~]# wc /etc/hosts
-bash: wc: command not found


[root@jindada ~]# mv /usr/bin/gl /usr/bin/wc
[root@jindada ~]# wc /etc/hosts
2 10 158 /etc/hosts


[root@jindada ~]# mv /usr/bin/wc /usr/sbin/
[root@jindada ~]# wc /etc/hosts
-bash: /usr/bin/wc: No such file or directory
[root@jindada ~]# hash -d wc
[root@jindada ~]# wc /etc/hosts
2 10 158 /etc/hosts


#清空hash缓存表中的所有缓存

[root@jindada ~]# hash -r
[root@jindada ~]# hash
hash: hash table empty

#里面存放的是系统中的命令的路径,每个路径用:号分割

[root@jindada ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

 

第十七章 文件的执行过程

原文:https://www.cnblogs.com/jhno1/p/13324742.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!