Search code examples
linuxshellunixcommand-linedirectory-structure

Unix standard directory to put custom executables or scripts?


If I have a custom shell script or program 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?

/usr/bin ?
/usr/local/bin ?
/usr/lib ?
/usr/sbin ?
/bin ?
/sbin ?
/var ?

I usually put it under my ~/bin directory and add it to the PATH, but it doesn't seem clean. And every time I download a new program, I have to add it to the PATH again.


Solution

  • /usr/local/bin exists precisely for this purpose: for system-wide installation. For your own private use, ~/bin is the de facto standard.

    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:

    curl -o $HOME/downloads/fnord http://fnord.example.com/script.exe
    ln -s $HOME/downloads/fnord $HOME/bin/
    

    This assumes $HOME/bin is in your PATH.

    There are tools like stow which do this -- and much more -- behind the scenes for you.