在linux文件系统中,用户脚本应该放在哪里?

我正在考虑由 cron 调用的具体 python 脚本。

有帮助吗?

解决方案

我得到的信息:

/usr/local/sbin     custom script meant for root
/usr/local/bin      custom script meant for all users including non-root

来自 irc.debian.org #debian 的聊天日志片段:

(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.

感谢氢氧化物

其他提示

如果您谈论的是由用户创建的将从该用户 crontab 运行的脚本,我通常将它们放在主目录中的 bin 或 script 文件夹中,或者如果它们打算在用户之间共享,则将它们放在 / usr/local/scripts 目录。

对于谁感兴趣, 文件系统层次结构标准 (FHS) 是一个标准文档,仍然非常值得一读。我描述了几乎所有 Linux 发行版的基础,并得到了官方认可,例如经过 德班 和 Linux 标准库 (LSB)。

不过,你不会找到这个问题的任何肯定答案,因为......它没有定义;-)。我唯一能说的是:不要放在 /bin 中(也不放在 /usr/bin 中)。/usr/local/scripts 也很不寻常。$HOME/bin 似乎是一个可以接受的地方,前提是该脚本仅由该单个用户使用。

我坚信,如果一个文件是由用户创建的,那么它会进入他的用户目录(/home/username),如果他没有创建它,那么事情会变得更加复杂。我过去只是将它们放在 /usr/local/bin、/bin 或 /usr/local/scripts 中,我不确定 etch,但您需要检查以确保 /usr/local/脚本实际上位于 Cron 的 $PATH 中。

Debian 指南 对于 Ubuntu 来说非常有用:

通常,程序会自行安装在 /usr/local 子目录中。但是,Debian 软件包不得使用该目录,因为它是为系统管理员(或用户)私人使用而保留的

/usr/local/bin 根据指南似乎可以接受。

我个人把我的脚本放在 $HOME/.scripts.

我希望 LSB 能够具体解决这个问题。

/home/用户名/bin 怎么样?

将 ~/bin 添加到 $PATH 并使用 chmod +x 文件名使脚本可执行。

我个人更喜欢

/home/username/.bin

这样,bin 文件夹就被隐藏了,但您仍然可以将其添加到 PATH 中并执行其中包含 x 位的所有脚本。

我喜欢我的主目录干净(乍一看),文件夹很少。

您还可以添加 crontab 文件的路径,如 之前的 cron 相关问题.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top