Where to store bash scripts that all users may execute on Debian?

7

4

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?

rubo77

Posted 2013-05-15T12:24:27.023

Reputation: 2 822

3/usr/local/bin is the usual place for this – Nifle – 2013-05-15T12:26:34.083

Answers

9

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:

  1. Create the directory (I am assuming you have sudo configured, if not just switch to root with su) and allow execution:

    sudo mkdir /usr/local/scripts
    sudo chmod 755 /usr/local/scripts
    
  2. 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"

terdon

Posted 2013-05-15T12:24:27.023

Reputation: 45 216

In debian PATH is set globally in /etc/environment. BTW, since Squeeze, Bash is no longer default shell. Dash is. – Michał Šrajer – 2013-05-15T13:27:31.673

I 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? – rubo77 – 2013-05-15T16:27:57.453

Strictly 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). – terdon – 2013-05-15T16:36:25.200