Where to store bash scripts that all users may execute on Debian?
The "official" place for local executables is /usr/local/bin
. This directory is usually in the $PATH of all users by default. Traditionally, programs that are not installed through a package manager (eg apt
) are stored in the /usr/local/bin
directory and those installed by the package manager in /usr/bin
. See here for some more information and here for the official definitions and more details than you will ever need.
These are just conventions though and you are free to use your own directory. For example, to store scripts that can be executed by all users in /usr/local/scripts
you would need to follow these steps:
-
Create the directory (I am assuming you have
sudo
configured, if not just switch toroot
withsu
) and allow execution:sudo mkdir /usr/local/scripts sudo chmod 755 /usr/local/scripts
-
Add this directory to all user's $PATHs (this assumes everyone is using bash). Add this line to
/etc/profile
:export PATH=$PATH:/usr/local/scripts
A better way (as @Michał Šrajer pointed out in the comments) that will work for most shells (at least any that use the pam_env
module would be to set the $PATH in /etc/environment
. For example:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/scripts"
Related videos on Youtube
rubo77
Updated on September 18, 2022Comments
-
rubo77 over 1 year
I have many bash scripts on my server, that all users may use.
but it seems the location
/usr/local/sbin
is not the best place.
I don't want to use the home directory of the users, cause everybody may execute them.
is there a convention about where to store them on Debian?
-
Admin about 11 years
/usr/local/bin
is the usual place for this
-
-
Michał Šrajer about 11 yearsIn debian
PATH
is set globally in/etc/environment
. BTW, since Squeeze, Bash is no longer default shell. Dash is. -
rubo77 about 11 yearsI wonder why I should store a plain-text script in a folder called "bin" or "sbin"? Aren't "binaries" compiled files, that are non-text?
-
terdon about 11 yearsStrictly speaking yes, that is what binaries are. However, by convention all executables are stored in the various
bin
directories. For example, on my system,/usr/bin
contains 2061 compiled binary files and 3888 scripts (text files).