众所周知,当我们在linux下执行一条命令时,发什么了些什么:
当执行一条命令时,系统首先查找shell中的hash哈希缓存,如果存在就直接引用。
否则,则需要遍历PATH环境变量所指向的目录来查找
[root@bogon ~]# hash
hits command
1 /sbin/ifconfig
1 /usr/bin/who
[root@bogon ~]#
哈希:
Key value
哈希以键为查找标准作比对,找到对应键后,其对应的值则为所需要的结果。
*如果随意修改删除$PATH将无法执行任何命令
[root@bogon ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
例如:当运行ifconfig时,会判断是内部命令还是外部命令,
系统在执行外部命令时,会先查看,如果找到就运行,如果找不到,则查找PATH变量目录来查找。路径通过使用冒号分割,且查找次序为从左到右,
。
[root@bogon ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:37:4F:2E
inet addr:192.168.47.130 Bcast:192.168.47.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe37:4f2e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:268 errors:0 dropped:0 overruns:0 frame:0
TX packets:167 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:31771 (31.0 KiB) TX bytes:21735 (21.2 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:6 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:344 (344.0 b) TX bytes:344 (344.0 b)
virbr0 Link encap:Ethernet HWaddr 52:54:00:86:84:42
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)