Linux

/bin和/sbin的区别,/usr/bin和/usr/sbin的区别及简单说明

1 /bin

全称binary,二进制文件,可以执行的文件。通常是用于单用户模式执行的命令,包含启动系统、恢复系统的命令。例如:cat,ls,cp,bash等。

[root@localhost ~]# ll /bin/ls
-rwxr-xr-x. 1 root root 109208 11月 22 2013 /bin/ls
[root@localhost ~]# ll /bin/cat 
-rwxr-xr-x. 1 root root 45224 11月 22 2013 /bin/cat
[root@localhost ~]# ll /bin/cp
-rwxr-xr-x. 1 root root 116824 11月 22 2013 /bin/cp
[root@localhost ~]# ll /bin/bash 
-rwxr-xr-x. 1 root root 903336 7月  18 2013 /bin/bash
[root@localhost ~]#

2 /sbin

system binary,系统可执行二进制文件。通常包含启动系统的命令,这些命令一般不给普通用户执行。例如:init,halt,mkfs.xfs,fsck,nologin等。

[root@localhost ~]# ll /sbin/init
-rwxr-xr-x. 1 root root 150352 6月  25 2013 /sbin/init
[root@localhost ~]# ll /sbin/halt 
lrwxrwxrwx. 1 root root 6 9月  19 2016 /sbin/halt -> reboot
[root@localhost ~]# ll /sbin/mkfs.xfs 
-rwxr-xr-x. 1 root root 290768 11月 23 2013 /sbin/mkfs.xfs
[root@localhost ~]# ll /sbin/fsck
-rwxr-xr-x. 1 root root 32088 11月 22 2013 /sbin/fsck
[root@localhost ~]# ll /sbin/nologin 
-rwxr-xr-x. 1 root root 4736 11月 22 2013 /sbin/nologin
[root@localhost ~]# 

3 /usr/bin

User System Resources,,binary。Non-essential command binaries (not needed in single-user mode); for all users.

Secondary hierarchy for read-only user data; contains the majority of (multi-)user utilities and applications. Should be shareable and read-only.

Wikipedia:https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard

/usr is shareable, read-only data. That means that /usr should
be shareable between various FHS-compliant hosts and must not be written to.
Any information that is host-specific or varies with time is stored elsewhere.

Large software packages must not use a direct subdirectory under the /usr
hierarchy. 
Linux Filesystem Hierarchy:
https://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/usr.html        

共享的,只读的,用于用户使用的一些命令。由于历史遗留原因,以前usr其实是表示user的意思,即用户的个人数据,后面用户的数据迁移到/home/username之后,该usr就用于表示user system resource了。

通常,也认为该路径下是在系统上安装的给普通用户使用的命令。如:zip,mysql等可执行程序。

[root@localhost ~]# ll /usr/bin/mysql
-rwxr-xr-x. 1 root root 9833910 11月 21 2014 /usr/bin/mysql
[root@localhost ~]# ll /usr/bin/zip
-rwxr-xr-x. 1 root root 212048 11月 10 2015 /usr/bin/zip
[root@localhost ~]# which mysql
/usr/bin/mysql
[root@localhost ~]# which zip
/usr/bin/zip
[root@localhost ~]# 

4 /usr/sbin

User System Resources,,system binary。Non-essential system binaries (e.g., daemons for various network services).

安装在系统上的,用于系统管理维护的命令。如:crond

[root@localhost ~]# ll /usr/sbin/visudo 
-rwxr-xr-x. 1 root root 154680 11月 22 2013 /usr/sbin/visudo
[root@localhost ~]# ll /usr/sbin/crond 
-rwxr-xr-x. 1 root root 64096 8月  24 2016 /usr/sbin/crond
[root@localhost ~]# 

5 /usr/local/bin

This is where programs which are local to the site typically go.

If you want to create your own scripts and make them available to all users, you’re pretty safe adding them to /usr/local/bin.

What I do is add my scripts to my local bin (~/bin) and then I create a symbolic link in /usr/local/bin to the commands I want to make public. As a result, I can manage all my scripts from the same directory but still make some of them publicly available since /usr/local/bin is added to $PATH.

比如,我们在Linux服务器上安装完Oracle软件之后,会在/usr/local/bin路径下创建几个和Oracle数据库软件相关的可执行程序:

[root@localhost ~]# ll /usr/local/bin/
总用量 20
-rwxr-xr-x. 1 oracle root 4143 11月 30 2016 coraenv
-rwxr-xr-x. 1 oracle root 2415 11月 30 2016 dbhome
-rwxr-xr-x. 1 oracle root 5036 11月 30 2016 oraenv
[root@localhost ~]# 

6参考链接

https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard

https://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/usr.html

留言