If I have a custom shell script or programs, 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 folder and put it in PATH, but it doesn't seem clean. And everytime I downloaded a new program, I have to put it in the PATH again.
If your scripts are intended to run by a single user you can place them in ~/bin. If your scripts are system-wide you can probably place them in /usr/local/bin. If your scripts are meant to be only used under special circumstances or environments you can put them even in /opt/myscripts and add this directory to $PATH.
/usr/local/bin is often on the path by default. Note that you should only put the executable or a link to it in /usr/local/bin , the rest may have to go in /usr/local/lib or /usr/local/share .
If any user on the system should be able to run the script, put it in /usr/local/bin . Don't put scripts you write yourself in /bin or /usr/bin . Those directories are intended for programs managed by the operating system.
The '/bin' directory also contains executable files, Linux commands that are used in single user mode, and common commands that are used by all the users, like cat, cp, cd, ls, etc. According to the FHS the /bin directory should contain /bin/cat and /bin/date (among others).
/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/
provided $HOME/bin
is in your PATH
. (There are tools like stow
which do this -- and much more -- behind the scenes for you.)
This may vary slightly depending on the Unix flavour. I'm assuming Linux here (although this could apply to OSX). According to the Filesystem Hierarchy Standard (FHS) (link obtained from the Linux Standard Base working group):
The
/usr/local
hierarchy is for use by the system administrator when installing software locally. It needs to be safe from being overwritten when the system software is updated. It may be used for programs and data that are shareable amongst a group of hosts, but not found in/usr
.Locally installed software must be placed within
/usr/local
rather than/usr
unless it is being installed to replace or upgrade software in/usr
.
/usr/local/bin
is often on the path by default.
Note that you should only put the executable or a link to it in /usr/local/bin
, the rest may have to go in /usr/local/lib
or /usr/local/share
.
The /opt
tree might also be sensible:
/opt
is reserved for the installation of add-on application software packages.A package to be installed in /opt must locate its static files in a separate
/opt/<package>
or/opt/<provider>
directory tree, where<package>
is a name that describes the software package and<provider>
is the provider's LANANA registered name.[...]
The directories /opt/bin, /opt/doc, /opt/include, /opt/info, /opt/lib, and /opt/man are reserved for local system administrator use. Packages may provide "front-end" files intended to be placed in (by linking or copying) these reserved directories by the local system administrator, but must function normally in the absence of these reserved directories.
(You could make your own link from /opt/your-package/bin/executable
into /opt/bin
, and put /opt/bin
on the PATH
if it's not already there.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With