1. Overview
All Linux flavors follow a specific FHS (Filesystem Hierarchy Standard). The Linux Foundation maintains FHS. In general, everything in the Linux operating system is a file. However, all files aren’t stored at the same location, as each serves a unique purpose.
In this tutorial, we’ll first understand the directory structure of Linux systems. Then, we’ll learn the purpose of different paths such as /bin, /sbin, /usr/bin, and others.
Also, let’s note that we may use words like mount and directory implying the same meaning because mount points are directories that serve as access points for files or directories.
2. Directory Layout
All Linux distributions have more or less the same directory layout. A directory is a cataloging feature for maintaining files. Files can reside on different physical or virtual devices. There are numerous directories and subdirectories.
To clarify, let’s look at a few of the top-level ones briefly:
- /root – parent directory, accessible to root
- /bin – this is where all types of binaries reside
- /boot – important files needed while booting such as kernel files, bootloader files
- /etc – configuration files of programs, commonly*.conf*
- /dev – device access files such as terminals
- /opt – optional software packages installed by individual users
- /lib – libraries essential for binaries on the system
- /mnt – mounted filesystems
- /var – constantly changing data such as log files
Files are stored inside either these directories or subdirectories of these. However, in this article, we’ll focus on the*/bin* directory, where we store binary files.
Notably, we see there’s more than one subdirectory mounted for binaries. We’ll steadily shed light on each of them.
3. Binary Directories
On the whole, a binary file is a sequence of bits, i.e., zeros and ones, that encode information. One of the most common binary file types is an executable object. We can also call it a computer program. Other types of binary files are archives, images, audio and video files, and others.
Some executable files can be essential to the OS, but some are additions and extras. Based on their usage, the OS stores them inside different directories. Let’s dive into using different directories where we store binaries and understand them.
3.1. /bin
The /bin directory contains binaries that are essential to the operating system.
For instance, programs like ls, cat, and others are essential programs. After the OS boots, we need such programs to perform basic Linux operations in single-user mode. Normal system users should avoid fiddling with these files, because it may lead to disruptions of some basic OS functions.
Let’s see how /bin directory listing looks like:
$ ls /bin
chmod dash df expr ksh ln mv pwd rmdir stty test zsh
bash cp date echo hostname launchctl ls pax realpath sh sync unlink
cat csh dd ed kill link mkdir ps rm sleep tcsh wait4path
...
These are some typical files that exist in the /bin directory.
3.2. /sbin
The /sbin name stands for system binary. It’s distinct from /bin in a very minute way.
For the most part, the /sbin directory stores the binaries required by the operating system for system management. Binaries stored in /sbin include ifconfig, fdisk, init, shutdown, systemd, and similar*.* These require root privileges to execute. For this reason, normal users of the system shouldn’t operate with these.
Let’s see a snippet of /sbin directory listing:
$ ls /sbin/
dmesg fdisk fstyp_udf ifconfig init
mknod mount_ftp ping route reboot
shutdown systemd
...
Here, we see some common files for /sbin.
3.3. /usr/bin
The /usr directory can store all read-only files that can be shared among users. When normal users install software on the system, the binaries usually go to /usr/bin and the libraries – to /usr/lib. We don’t need these binaries for booting or repairing the system. In essence, normal users employ these executable programs and files. Programs like diff, du, and scp are some common examples of binaries that go in /usr/bin.
The snippet below shows exactly the path where these programs are located in the system:
$ which diff
/usr/bin/diff
$ which du
/usr/bin/du
$ which scp
/usr/bin/scp
Notably, these are mainly tools and all are in the /usr/bin directory.
3.4. /usr/sbin
Again, the subdirectory /sbin under /usr isn’t for all users. The binaries stored in /usr/sbin are executable programs, mostly used by system administrators, usually superusers. These programs require root permissions. In other words, normal users mostly don’t interfere with the contents of /usr/sbin. For this path, programs like sshd, chown, iostat are some common examples:
$ which sshd
/usr/sbin/sshd
$ which chown
/usr/sbin/chown
$ which iostat
/usr/sbin/iostat
We see some important binaries in the /usr/sbin path.
3.5. /usr/local/bin
There is a subdirectory called /local inside the /usr directory, specifically to store local binaries. These binaries are local to system users and system packages don’t manage them. Some Linux distributions update packages automatically. But in this case, such local binaries won’t update. Users can install programs in this location without any hesitations that they’ll get replaced.
Programs such as wget, python3, and git are some common examples of local user packages:
$ which wget
/usr/local/bin/wget
$ which python3
/usr/local/bin/python3
$ which git
/usr/local/bin/git
As expected, these are all userland tools.
3.6. /usr/local/sbin
The binaries locally installed for system administrators reside in the /usr/local/sbin path. Only user permissions make it distinct from the /usr/local/bin. Particularly, users other than the system admin shouldn’t install and store any programs inside the /usr/local/bin directory. Utilities like Wireshark and Nmap are common residents of this path.
Let’s see an example of an /sbin directory listing:
$ ls /usr/local/sbin/
nmap wireshark
Thus, each /bin directory or subdirectory plays a unique role in the directory layout of a Linux system.
4. System Definitions
When discussing filesystems, it’s important that we see the filesystem hierarchy. On the Linux system, we can check the detailed layout of filesystems by using the command hier. It describes all major default directories and subdirectories, such as /bin, /dev, /etc, /usr, /var, and others.
Additionally, the man page for hier comes with all Linux distributions by default, as it’s defined by the Filesystem Hierarchy Standard:
$ 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
In this case, we list the hier documentation and filter it via grep extended regular expressions to list only binary directories and the first two lines of their description.
In essence, the above information depicts how various files are stored at different locations and those locations do serve a unique purpose. Likewise, it helps when we write a program and want to execute it from multiple locations.
5. Conclusion
To summarize, we have various types of binaries, and each is stored under specific subdirectories.
In this article, we first looked at the directory layout. Then, we learned how binary files are stored. Finally, we studied the intention behind binary file directories on a Linux system.