Linux 用于放置自定义可执行文件或脚本的 Unix 标准目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9168432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unix standard directory to put custom executables or scripts?
提问by atedja
If I have a custom shell script or programs, that I created myself or downloaded from the web, and I want to be able to execute this from the CLI, is there the standard location to put this in Linux/Unix directory structure?
如果我有一个自定义的 shell 脚本或程序,是我自己创建的或从 Web 下载的,并且我希望能够从 CLI 执行它,是否有将它放在 Linux/Unix 目录结构中的标准位置?
/usr/bin ?
/usr/local/bin ?
/usr/lib ?
/usr/sbin ?
/bin ?
/sbin ?
/var ?
I usually put it under my ~/bin folder and put it in PATH, but it doesn't seem clean. And everytime I downloaded a new program, I have to put it in the PATH again.
我通常把它放在我的 ~/bin 文件夹下并放在 PATH 中,但它看起来并不干净。每次下载新程序时,我都必须再次将其放入 PATH 中。
采纳答案by tripleee
/usr/local/bin
exists precisely for this purpose, for system-wide installation. For your own private use, ~/bin
is the de facto standard.
/usr/local/bin
正是为此目的而存在的,用于系统范围的安装。供您私人使用,~/bin
是事实上的标准。
If you want to keep each binary in its own subdirectory, you can do that, and add a symlink to a directory already in your PATH
. So, for example
如果您想将每个二进制文件保存在其自己的子目录中,您可以这样做,并将符号链接添加到PATH
. 所以,例如
curl -o $HOME/downloads/fnord http://fnord.example.com/script.exe
ln -s $HOME/downloads/fnord $HOME/bin/
provided $HOME/bin
is in your PATH
. (There are tools like stow
which do this -- and much more -- behind the scenes for you.)
提供$HOME/bin
在您的PATH
. (有类似的工具stow
可以在幕后为您执行此操作 - 以及更多。)
回答by Bruno
This may vary slightly depending on the Unix flavour. I'm assuming Linux here (although this could apply to OSX). According to the Filesystem Hierarchy Standard (FHS)(link obtained from the Linux Standard Base working group):
这可能会因 Unix 风格而略有不同。我在这里假设是 Linux(尽管这可能适用于 OSX)。根据Filesystem Hierarchy Standard (FHS)(从Linux Standard Base 工作组获得的链接):
The
/usr/local
hierarchy is for use by the system administrator when installing software locally. It needs to be safe from being overwritten when the system software is updated. It may be used for programs and data that are shareable amongst a group of hosts, but not found in/usr
.Locally installed software must be placed within
/usr/local
rather than/usr
unless it is being installed to replace or upgrade software in/usr
.
该
/usr/local
层次结构供系统管理员在本地安装软件时使用。它需要在系统软件更新时不会被覆盖。它可用于在一组主机之间共享的程序和数据,但在/usr
.本地安装的软件必须置于
/usr/local
而非/usr
除非正在安装它来取代或升级软件/usr
。
/usr/local/bin
is often on the path by default.
/usr/local/bin
默认情况下通常在路径上。
Note that you should only put the executable or a link to it in /usr/local/bin
, the rest may have to go in /usr/local/lib
or /usr/local/share
.
请注意,您应该只将可执行文件或指向它的链接放入 中/usr/local/bin
,其余的可能必须放入/usr/local/lib
或 中/usr/local/share
。
The /opt
tree might also be sensible:
这/opt
棵树也可能是明智的:
/opt
is reserved for the installation of add-on application software packages.A package to be installed in /opt must locate its static files in a separate
/opt/<package>
or/opt/<provider>
directory tree, where<package>
is a name that describes the software package and<provider>
is the provider's LANANA registered name.[...]
The directories /opt/bin, /opt/doc, /opt/include, /opt/info, /opt/lib, and /opt/man are reserved for local system administrator use. Packages may provide "front-end" files intended to be placed in (by linking or copying) these reserved directories by the local system administrator, but must function normally in the absence of these reserved directories.
/opt
保留用于安装附加应用程序软件包。要安装在 /opt 中的软件包必须在单独的
/opt/<package>
或/opt/<provider>
目录树中定位其静态文件,其中<package>
是描述软件包的名称,<provider>
是提供商的 LANANA 注册名称。[...]
目录 /opt/bin、/opt/doc、/opt/include、/opt/info、/opt/lib 和 /opt/man 保留供本地系统管理员使用。包可能提供旨在由本地系统管理员放置(通过链接或复制)这些保留目录中的“前端”文件,但必须在没有这些保留目录的情况下正常运行。
(You could make your own link from /opt/your-package/bin/executable
into /opt/bin
, and put /opt/bin
on the PATH
if it's not already there.)
(您可以从/opt/your-package/bin/executable
into制作自己的链接/opt/bin
,如果尚未存在/opt/bin
,PATH
则将其放入。)