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?



2 Answers 2


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/.

  • 2
    Does placing scripts in /bin cause any problems? I have moved my scripts according to your answer but I am still curious
    – Rumesh
    Commented Apr 27, 2015 at 12:14
  • 10
    @RumeshSudhaharan you should not do that, because it's managed by the package management. If any other package also wants to use that path, it will overwrite your file. Files in packages can never overlap (at least for official repositories), so you are more safe when installing in the local path. Also, it's just for your own convenience and safety. In a local path you can't mess up the system in such a bad way and you can't accidentally replace a system binary.
    – gertvdijk
    Commented Apr 27, 2015 at 12:17
  • 14
    I like the explanation on the error page : Severity:Serious Certainty:Certain
    – cutrightjm
    Commented Nov 25, 2015 at 6:15
  • 2
    I have put some files in /usr/local/bin and I can execute them, however I cannot edit them, ls -la shows nothing Commented Mar 19, 2018 at 13:52
  • 4
    FWIW, sbin has nothing to do with scripts. It stores binaries - even the links provided note that.
    – user260281
    Commented Sep 14, 2018 at 9:58

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:

$ 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.

              Binaries  which  belong  to the X-Window system; often, there is a symbolic
              link from the more traditional /usr/bin/X11 to here.
              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
              Binaries for programs local to the site.

              Locally installed programs for system administration.

              This directory contains program binaries for  system  administration  which
              are  not  essential  for the boot process, for mounting /usr, or for system

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 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?

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.

  • 1
    I appreciate your effort, but , except the "What I know I don't know" part, you repeated gertvdijk's answer.
    – danzel
    Commented Jun 11, 2018 at 23:54
  • 2
    @danzel I think the key part is the man hier section which gertvdijk's answer didn't address. ie you can get the directory hierarchical structure in the command line without having to resort to reading it on the web (ie here). Commented Jun 11, 2018 at 23:56
  • 1
    that is interesting information, I agree. But gertvdijk already mentioned the Filesystem Hierarchy Standard (which man hier is an informationally insufficient excerpt of IMO). However, this may be my personal opinion.
    – danzel
    Commented Jun 12, 2018 at 0:11
  • 1
    @danzel I agree websites have a lot more in-depth analysis than what's on our hard drives. I'm only trying to point out the information is on our hard drives without resorting the Internet. Besides the wikipedia link quoted is missing /usr/X11R6/bin and /usr/local/bin which is included in man heir. Commented Jun 12, 2018 at 0:26
  • @WinEunuuchs2Unix, re last para; Why not /usr/local/bin since you're not the package manager?
    – Pacerier
    Commented Jul 20, 2019 at 7:09

You must log in to answer this question.