linux中的/bin与/usr/bin

有一些开源项目在make构建的时候会调用一些shell脚本,我发现这些shell脚本的shebang有一些微妙之处:

  • /usr/bin/env bash
  • /usr/bin/bash
  • /bin/bash

第一种我就不讨论了,主要是后面两种,我老是傻傻的分不清,今天找了个时间,到服务器上一看,傻眼了。
阿里云机器的centos 7

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[root@iz2zefvnzjphkalt990sg0z /]# uname -a
Linux iz2zefvnzjphkalt990sg0z 3.10.0-693.2.2.el7.x86_64 #1 SMP Tue Sep 12 22:26:13 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@iz2zefvnzjphkalt990sg0z /]# ll /
总用量 72
lrwxrwxrwx. 1 root root 7 10月 15 2017 bin -> usr/bin
dr-xr-xr-x. 5 root root 4096 10月 15 2017 boot
drwxr-xr-x 20 root root 3040 5月 14 18:09 dev
drwxr-xr-x. 88 root root 12288 5月 21 12:46 etc
drwxr-xr-x. 2 root root 4096 11月 5 2016 home
lrwxrwxrwx. 1 root root 7 10月 15 2017 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 10月 15 2017 lib64 -> usr/lib64
drwx------. 2 root root 16384 10月 15 2017 lost+found
drwxr-xr-x. 2 root root 4096 11月 5 2016 media
drwxr-xr-x. 2 root root 4096 11月 5 2016 mnt
drwxr-xr-x. 2 root root 4096 11月 5 2016 opt
dr-xr-xr-x 73 root root 0 5月 14 18:09 proc
dr-xr-x---. 14 root root 4096 5月 21 12:45 root
drwxr-xr-x 24 root root 740 5月 21 12:54 run
lrwxrwxrwx. 1 root root 8 10月 15 2017 sbin -> usr/sbin
drwxr-xr-x 3 root root 4096 12月 9 16:30 soft
drwxr-xr-x. 3 root root 4096 12月 21 18:03 srv
dr-xr-xr-x 13 root root 0 5月 15 02:09 sys
drwxrwxrwt. 9 root root 4096 5月 21 12:52 tmp
drwxr-xr-x. 13 root root 4096 10月 15 2017 usr
drwxr-xr-x. 21 root root 4096 5月 10 16:40 var
[root@iz2zefvnzjphkalt990sg0z /]#

公司的测试环境centos 5.5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[deploy@baochai /usr]$ uname -a
Linux baochai 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
[deploy@baochai /usr]$ ll /
total 158
lrwxrwxrwx 1 root root 14 Jul 31 2015 appdata -> /data/appdata/
lrwxrwxrwx 1 root root 17 Jul 24 2015 applogs -> /data/log/applogs
dr-xr-xr-x. 2 root root 4096 Mar 14 04:46 bin
dr-xr-xr-x. 5 root root 1024 Jul 22 2015 boot
drwxr-xr-x. 2 root root 4096 Oct 18 2014 cgroup
drwxr-xr-x. 16 root root 4096 Mar 6 16:41 data
lrwxrwxrwx 1 root root 16 Jul 24 2015 deployment -> /data/deployment
drwxr-xr-x 17 root root 3700 May 8 11:08 dev
drwxr-xr-x. 118 root root 12288 May 20 03:37 etc
drwxr-xr-x. 46 root root 4096 May 15 18:00 home
dr-xr-xr-x. 11 root root 4096 Jun 14 2017 lib
dr-xr-xr-x. 9 root root 12288 Mar 7 03:27 lib64
drwx------. 2 root root 16384 Jul 22 2015 lost+found
drwxr-xr-x. 2 root root 4096 Sep 23 2011 media
drwxr-xr-x. 2 root root 4096 Nov 23 2013 misc
drwxr-xr-x. 2 root root 4096 Sep 23 2011 mnt
drwxr-xr-x. 2 root root 4096 Nov 23 2013 net
drwxr-xr-x. 6 root root 4096 Mar 28 15:59 opt
dr-xr-xr-x 1418 root root 0 Apr 29 05:19 proc
dr-xr-x---. 27 root root 4096 May 17 08:49 root
dr-xr-xr-x. 2 root root 12288 Dec 16 03:45 sbin
drwxr-xr-x. 2 root root 4096 Jul 22 2015 selinux
drwxr-xr-x. 2 root root 4096 Sep 23 2011 srv
drwxr-xr-x 13 root root 0 Apr 29 05:19 sys
drwxr-xr-x 3 root root 4096 Oct 11 2016 tep
drwsrwsrwt 60 root root 36864 May 21 14:20 tmp
drwxr-xr-x. 14 root root 4096 Jul 16 2016 usr
drwxr-xr-x. 23 root root 4096 Apr 28 15:03 var
[deploy@baochai /usr]$

WTF,在centos7下面,/bin其实就是/usr/bin,lib就是/usr/lib/,sbin就是/usr/sbin。