367 filesystem command-line scripts system directory
我有六个带有命令文件的目录。这是/bin
,/sbin
,/usr/bin
,/usr/sbin
,/usr/local/bin
和/usr/local/sbin
。
这些之间有什么区别?如果我正在编写自己的脚本,我应该在哪里添加它们?
有关的:
ger*_*ijk 435
为此,请参阅Linux的文件系统层次结构标准 (FHS)。
/bin
:对于在/usr
安装分区之前可用的二进制文件。这用于在非常早期的引导阶段或在引导单用户模式下需要可用的简单二进制文件。认为这样的二进制文件cat
,ls
等等。
/sbin
:相同,但对于需要超级用户(root)权限的二进制文件。
/usr/bin
:与第一个相同,但适用于一般系统范围的二进制文件。
/usr/sbin
: 同上,但对于需要超级用户(root)权限的二进制文件。
如果我正在编写自己的脚本,我应该在哪里添加这些脚本?
以上都不是。您应该使用/usr/local/bin
或/usr/local/sbin
系统范围内可用的脚本。该local
路径意味着它不是由系统包(这是管理错误适用于Debian / Ubuntu的软件包)。
对于用户范围的脚本,请使用~/bin
(主目录中的个人 bin 文件夹)。
FHS 表示/usr/local
:
本地数据的三级层次结构,特定于此主机。通常具有进一步的子目录,例如
bin/
,lib/
,share/
。
Win*_*nix 22
一年多以前,我自己也遇到过类似的问题:放置 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
Run Code Online (Sandbox Code Playgroud)
对于所有用户访问您的脚本,您可以将它们放在/usr/local/bin
. 请记住,您需要sudo
在此处添加/更改文件的访问权限。请参阅:是否有放置自定义 Linux 脚本的标准位置?
对于您自己的用户 ID 脚本,请将它们放在/home/YOUR_NAME/bin
. 请记住,您必须先创建此目录并重新启动终端才能通过~/.profile
. 请参阅:如何将 /home/username/bin 添加到 $PATH?
我正在考虑在Ask Ubuntu 中使用一些更复杂的 bash 脚本,并在github
. 以下是几个例子:
我认为脚本应该安装在/usr/bin
$PATH中的哪个位置,但我不确定在合适的位置。
归档时间: |
|
查看次数: |
278506 次 |
最近记录: |