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 likecat
,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.None of the above. You should use
/usr/local/bin
or/usr/local/sbin
for system-wide available scripts. Thelocal
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
:I had a similar question myself a year+ ago: Best directory to place my bash scripts?
System directories for binaries
man hier
(hierarchy) lists all the directories. To get the ones just for binaries use:Where to put your own scripts?
For all users to access your scripts you can put them in
/usr/local/bin
. Keep in mind you needsudo
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?What I know I don't know
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.