/ bin,/ sbin,/ usr / bin,/ usr / sbin,/ usr / local / bin,/ usr / local / sbin之间的区别
我有六个目录与命令文件。 这些是/bin
, /sbin
, /usr/bin
, /usr/sbin
, /usr/local/bin
和/usr/local/sbin
。
这些有什么区别? 如果我正在编写自己的脚本,我应该在哪里添加它们?
有关:
- 如何理解Ubuntu文件系统布局?
- Linux上的/ usr / bin vs / usr / local / bin
- 我应该把我的bash脚本放在哪里
有关此信息,请参阅Linux的文件系统层次结构标准(FHS) 。
-
/bin
:对于在挂载/usr
分区之前可用的二进制文件。 这用于在早期启动阶段使用的普通二进制文件,或者在启动单用户模式时需要可用的二进制文件。 想想像cat
,cat
等的二进制文件。 -
/sbin
:相同,但对于需要超级用户(root)权限的二进制文件。 -
/usr/bin
:与第一个相同,但适用于一般系统范围的二进制文件 。 -
/usr/sbin
:与上面相同,但是对于需要超级用户(root)权限的二进制文件。
如果我正在编写自己的脚本,我应该在哪里添加这些脚本?
以上都不是。 您应该使用/usr/local/bin
或/usr/local/sbin
来获取系统范围的可用脚本。 local
路径意味着它不受系统包管理(这是Debian / Ubuntu包的错误 )。
对于用户范围的脚本 ,请使用~/bin
(主目录中的个人bin文件夹)。
FHS对/usr/local
:
本地数据的第三层次结构, 特定于此主机 。 通常具有其他子目录,例如
bin/
,lib/
,share/
。
一年前我有一个类似的问题: 放置我的bash脚本的最佳目录?
二进制文件的系统目录
man hier
(hierarchy)列出了所有目录。 要获得仅用于二进制文件的那些:
$ man hier | grep -E 'bin$|sbin$|^.{7}(/bin)|^.{7}(/sbin)' -A2 /bin This directory contains executable programs which are needed in single user mode and to bring the system up or repair it. -- /sbin Like /bin, this directory holds commands needed to boot the system, but which are usually not executed by normal users. -- /usr/X11R6/bin Binaries which belong to the X-Window system; often, there is a symbolic link from the more traditional /usr/bin/X11 to here. -- /usr/bin This is the primary directory for executable programs. Most programs exe‐ cuted by normal users which are not needed for booting or for repairing the -- /usr/local/bin Binaries for programs local to the site. -- /usr/local/sbin Locally installed programs for system administration. -- /usr/sbin This directory contains program binaries for system administration which are not essential for the boot process, for mounting /usr, or for system
在哪里放置自己的脚本?
要让所有用户访问您的脚本,您可以将它们放在/usr/local/bin
。 请记住,您需要sudo
访问权限才能在此处添加/更改文件。 请参阅: 是否有放置自定义Linux脚本的标准位置?
对于您自己的用户ID脚本,请将它们放在/home/YOUR_NAME/bin
。 请记住,您必须首先创建此目录并重新启动终端以通过~/.profile
自动设置路径。 请参阅: 如何将/ home / username / bin添加到$ PATH?
我所知道的我不知道
我正在考虑在Ask Ubuntu中使用一些更复杂的bash脚本,并在github
上使用安装脚本进行设置。 以下是一些例子:
- 根据日出和日落自动调整显示亮度
- 用于同时设置不同警报的计时器
- 在Ubuntu设定的时间后锁定屏幕的应用程序
- 本地文件和AU答案之间的代码版本控制
我认为这些脚本应该安装在$ PATH中的/usr/bin
中,但我还不确定它在适当的位置。