我自己一年多前也有一个类似的问题:
最佳目录放置我的bash脚本?
系统二进制文件的目录
man hier
(层次结构)列出了所有的目录。要获取仅用于二进制文件的目录,请使用:
$ 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
上的安装脚本结合起来。以下是一些示例:
我认为脚本应该安装在$PATH中的/usr/bin目录下,但是我还不确定适当的位置。
~/.local/bin
目录中。更多信息请参考这里和这里的答案。 - Matthias Braun