在linux文件系统中,用户脚本应该放在哪里?
我正在考虑专门由 cron 调用的 python 脚本。
我得到的信息:
1 2
| /usr/local/sbin custom script meant for root
/usr/local/bin custom script meant for all users including non-root |
来自 irc.debian.org #debian:
的聊天记录Fragments
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| (02:48:49) c33s: question: where is the _correct_ location, to put custom scripts
for the root user (like a script on a webserver for createing everything needed
for a new webuser)? is it /bin, /usr/local/bin,...? /usr/local/scripts is
mentioned in (*link to this page*)
(02:49:15) Hydroxide: c33s: typically /usr/local/sbin
(02:49:27) Hydroxide: c33s: no idea what /usr/local/scripts would be
(02:49:32) Hydroxide: it's nonstandard
(02:49:53) Hydroxide: if it's a custom script meant for all users including
non-root, then /usr/local/bin
(02:52:43) Hydroxide: c33s: Debian follows the Filesystem Hierarchy Standard,
with a very small number of exceptions, which is online in several formats at
http://www.pathname.com/fhs/ (also linked from http://www.debian.org/devel/ and
separately online at http://www.debian.org/doc/packaging-manuals/fhs/fhs-2.3.html)
(02:53:03) Hydroxide: c33s: if you have the debian-policy package installed, it's
also in several formats at /usr/share/doc/debian-policy/fhs/ on your system
(02:53:37) Hydroxide: c33s: most linux distributions follow that standard, though
usually less strictly and with more deviations than Debian. |
感谢 Hydroxide
如果您谈论的是由用户创建的脚本,这些脚本将从该用户的 crontab 运行,我通常将它们放在主目录的 bin 或 scripts 文件夹中,或者如果它们打算在用户之间共享, /usr/local/scripts 目录。
对于感兴趣的人来说,文件系统层次标准 (FHS) 是一个标准文档,并且仍然是一个很好的读物。我描述了几乎所有 Linux 发行版的基础,并得到官方认可,例如由 Debian 和 Linux 标准库 (LSB) 提供。
但是,您不会为该问题找到任何肯定的答案,因为......它没有定义;-)。我只能说:不要放入/bin(也不要放入/usr/bin)。 /usr/local/scripts 也很不寻常。 $HOME/bin 似乎是一个可以接受的地方,如果该脚本仅由该单个用户使用。
Debian 指南对于 Ubuntu 非常有用:
Normally, programs install themselves in the /usr/local subdirectories. But, Debian packages must not use that directory, since it is reserved for system administrator's (or user's) private use
/usr/local/bin 根据指南似乎是可以接受的。
我个人把我的脚本放在 $HOME/.scripts.
我希望 LSB 能专门解决这个问题。
我坚信如果一个文件是由用户创建的,如果他没有创建文件,它会进入他的用户目录(/home/username),那么它会变得更加复杂。我过去只是将它们放在 /usr/local/bin、/bin 或 /usr/local/scripts 中,我不确定 etch,但您需要检查以确保 /usr/local/脚本实际上在 Cron 的 $PATH 中。
我个人更喜欢
这样 bin 文件夹会被隐藏,但您仍然可以将其添加到 PATH 并执行所有带有 x 位的脚本。
我喜欢我的主目录干净(乍一看),文件夹很少。
/home/username/bin 怎么样?
将 ~/bin 添加到 $PATH 并使用 chmod x 文件名使脚本可执行。
您还可以将路径添加到您的 crontab 文件中,如上一个与 cron 相关的问题中所示。