A standard Unix directory for hosting custom executables or scripts?

If I have a custom shell script or programs that I created myself or downloaded from the Internet, and I want it to be able to be executed from the CLI, is there a standard directory structure for Linux / Unix?

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

Usually I put it in the ~ / bin folder and put it in PATH, but it does not look clean. And every time I download a new program, I have to put it in PATH again.

+50
command-line linux unix shell directory-structure
Feb 06 2018-12-12T00:
source share
3 answers

/usr/local/bin exists for this very purpose, for a system-wide installation. For your personal use, ~/bin is the de facto standard.

If you want to save each binary file in your subdirectory, you can do this and add a symbolic link to the directory already in PATH . So for example

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

if $HOME/bin is in your PATH . (There are tools like stow that do this - and much more - backstage for you.)

+65
Feb 06 2018-12-12T00:
source share

This may vary slightly depending on the taste of Unix. I assume Linux is here (although this may apply to OSX). According to the File System Hierarchy Standard (FHS) (link obtained from Linux Standard Basic Workgroup ):

The /usr/local hierarchy is intended for use by the system administrator when installing the software locally. It must be safe from being overwritten when updating system software. It can be used for programs and data that can be included in a host group, but not found in /usr .

Locally installed software must be located within /usr/local than /usr if it is not installed to replace or update software in /usr .

/usr/local/bin often located on the default path.

Please note that you should only place the executable file or a link to it in /usr/local/bin , the rest can go to /usr/local/lib or /usr/local/share .

The /opt tree may also be reasonable:

/opt reserved for installing additional software packages.

The package that must be installed in / opt must find its static files in a separate /opt/<package> or /opt/<provider> directory tree, where <package> is the name that describes the software package and <provider> is the registered name of the LANANA provider.

[...]

The directories / opt / bin, / opt / doc, / opt / include, / opt / info, / opt / lib, and / opt / man are reserved for use by the local system administrator. packages can provide front-end files designed to host (by linking or copying) these reserved directories by a local system administrator, but should function normally in the absence of these reserved directories.

(You can make your own link from /opt/your-package/bin/executable in /opt/bin and put /opt/bin in PATH if it does not already exist.)

+15
Feb 06 '12 at 23:12
source share

Well, I would use ~/bin (as long as I'm not root), but with respect to $PATH you can always do

 export PATH=".:${PATH}" # or export PATH="${PATH}:." 

That way, the actual working directory will always be in your $PATH . Although it has some security issues ... especially with loaded scripts.

-9
Feb 06 2018-12-12T00:
source share



All Articles