I have six directories with command files. These are /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin and /usr/local/sbin.
What are the differences between these? If I'm writing my own scripts, where should I add them?
Related:
I have six directories with command files. These are /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin and /usr/local/sbin.
What are the differences between these? If I'm writing my own scripts, where should I add them?
Related:
Please refer to the Filesystem Hierarchy Standard (FHS) for Linux for this.
/bin : For binaries usable before the /usr partition is mounted. This is used for trivial binaries used in the very early boot stage or ones that you need to have available in booting single-user mode. Think of binaries like cat, ls, etc.
/sbin : Same, but for binaries with superuser (root) privileges required.
/usr/bin : Same as first, but for general system-wide binaries.
/usr/sbin : Same as above, but for binaries with superuser (root) privileges required.
if I'm writing my own scripts, where should I add these?
None of the above. You should use /usr/local/bin or /usr/local/sbin for system-wide available scripts. The local path means it's not managed by the system packages (this is an error for Debian/Ubuntu packages).
For user-scoped scripts, use ~/bin (a personal bin folder in your home directory).
The FHS says for /usr/local:
Tertiary hierarchy for local data, specific to this host. Typically has further subdirectories, e.g.,
bin/,lib/,share/.
I had a similar question myself a year+ ago: Best directory to place my bash scripts?
man hier (hierarchy) lists all the directories. To get the ones just for binaries use:
$ man hier | grep -E 'bin$|sbin$|^.{7}(/bin)|^.{7}(/sbin)' -A2
/bin This directory contains executable programs which are needed in single user
mode and to bring the system up or repair it.
--
/sbin Like /bin, this directory holds commands needed to boot the system, but
which are usually not executed by normal users.
--
/usr/X11R6/bin
Binaries which belong to the X-Window system; often, there is a symbolic
link from the more traditional /usr/bin/X11 to here.
--
/usr/bin
This is the primary directory for executable programs. Most programs exe‐
cuted by normal users which are not needed for booting or for repairing the
--
/usr/local/bin
Binaries for programs local to the site.
--
/usr/local/sbin
Locally installed programs for system administration.
--
/usr/sbin
This directory contains program binaries for system administration which
are not essential for the boot process, for mounting /usr, or for system
For all users to access your scripts you can put them in /usr/local/bin. Keep in mind you need sudo access to add / change files here. See: Is there a standard place for placing custom Linux scripts?
For your own user ID scripts put them in /home/YOUR_NAME/bin. Keep in mind you have to create this directory first and relaunch the terminal to get the path automatically setup by ~/.profile. See: How to add /home/username/bin to $PATH?
I'm contemplating taking some of my more complex bash scripts in Ask Ubuntu and setting them up with install scripts on github. Here are few examples:
I think the scripts should be installed in /usr/bin which is in the $PATH, but I'm not sure on the appropriate place yet.