The Linux directory structure
The Linux directory structure
Linux directory structure – Chapter 9.3
This is the tenth of the free articles directly taken from the Manjaro Linux User Guide book, available at https://www.amazon.com/dp/B0C4PSWRQS/. The full list of freely available articles is here: Manjaro Linux User Guide – For newbies, fans, and mid users. More information at the end of the article.
Read time: 5 minutes. Previous article: 8.2 Pacman, Pamac, Octopi, And Package Management. Next article: 10.3 Backups, Tools, Rsync, And Recovery.
The FS Hierarchy standard
Now that we know file types and the most famous filesystems (FS) on Linux, let’s explore its FS directory structure. Linux has a stable structure, inherited initially from Unix and developed further. You will never again be confused once you know all the main directories and their usage. Before continuing, I recommend visually inspecting your directories with the Filelight GUI application. It provides an excellent HDD space usage analysis.
If you haven’t installed tree, just run $ pamac install tree. This command-line tool lists the directory structure up to a chosen level; find out more in Chapter 7.
It is important to note that there is a FS Hierarchy Standard (FHS), initially created for any Unix-like systems. Version 3.0 was issued in 2015 by the Linux Foundation. It is not a strict obligation but more of a recommendation. In addition, different distribution families have had different approaches to some of its parts over the years, so don’t expect Manjaro’s hierarchy to be the same as on other distributions. The standard is posted here: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html.
The Manjaro implementation
For Manjaro, the list of directories in the root directory / are as follows:
$ tree -d -L 1 / / ├── bin -> usr/bin ├── boot ├── dev ├── etc ├── home ├── lib -> usr/lib ├── lib64 -> usr/lib ├── lost+found ├── mnt ├── opt ├── proc ├── root ├── run ├── sbin -> usr/bin ├── srv ├── sys ├── tmp ├── usr └── var
In bold and with an arrow ->, we have symlinks to subdirectories that point to /usr ones. We will discuss them after we review each directory’s standard concepts:
/bin
This directory contains all binaries, including executables such as ls, exa, grep, cat, sysctl, pamac, chmod, etc.
/boot
The directory of the OS boot-related binaries, including the Linux kernel itself. It also contains the efi sub-directory with the efi bootloader and is typically located on /dev/sda1.
/dev
This is where all device files reside. When listing with $ exa -lah /dev/, you will see no regular files or binaries but mostly character and block device files.
/etc
This directory holds text configuration files. Examples include fstab, time zone, shell, terminal, user accounts and passwords, Xorg, and the graphical environment. The fastest way to inspect the configurations is by dumping them on the terminal with $ cat /etc/ filename, sometimes requiring sudo.
/home
The directory containing each user’s home directory. When we open the terminal, we always start on the /home/YourUserName path. It contains the regular Desktop, Documents, Downloads, and Pictures directories, and hidden files with user configurations such as .bashrc and .zshrc.
/lib and /lib64
Many SW applications depend on shared object libraries located here. Examples are libvlc.so, libturbojpeg.so, libsystemd.so, libQtxxx.so, libjson.so, libjpeg.so, libcamera.so, and thousands of others, preinstalled by the Manjaro team or installed by additional applications. lib64 has the suffix 64, as we have been working with 32-bit libraries for years, and initially, 64-bit versions were rare, separated in their own directory. Nowadays, many libraries have both versions, but we mainly use 64-bit software. Since many legacy applications count on one or the other directory, we keep them both.
/mnt
Empty by default, this directory is to temporarily mount FSs, HDD partitions, network locations, and other storage.
/opt
This directory was initially intended to install optional third-party SW with a symlink to it in the /bin directory. I have in my /opt an onlyoffice installation. Additional SW such as exa, tree, glances, and others are from the category “system software” (not optional), so they are typically installed in /bin. Thus, newly installed software will rarely be in /opt.
/proc
The directory for keeping information on all currently running processes. If we run $ ps -e, $ htop, or $ glances, we will get their list, identified by their Process Identifier (PID), explained in detail in Chapter 13. As on Manjaro, the boot and system manager is systemd – it has PID 1. In /proc, we have a directory named after the PID of each process, holding pointer files to its temporary data. Thus, it is a directory used by the Linux kernel, which we can use to investigate the processes. Read more about it here: https://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html.
/root
this is the root’s home directory; thus, we need to use sudo to list its contents with ls or exa. It contains the same directories as the standard user /home directory, such as Desktop, Documents, and Downloads. It also has the root .bashrc and other user-specific hidden configuration files. All of them are available to us when we log in to the system as the root user.
/run
This holds temporary directories, files, sockets, and other objects for currently running processes. It is relatively new; /proc existed before /run was accepted as an additional location.
/sbin
Originally, this was for system binaries and shall contain the init directory, and binaries only run by the root user. In the case of Manjaro, it is a link to /usr/bin.
/srv
This abbreviation is for service data, containing data for the system’s provided services. A typical example is if you run an HTTP server that hosts/provides a website on your machine, its data will be stored there. Currently, for Manjaro, it contains two directories, one for HTTP and one for FTP protocols. More on networking and protocols will be revealed in Chapters 11 and 12.
/sys
On Arch, Manjaro, and a few other distributions, this directory has a mounted pseudo-FS sysfs. It provides an interface to kernel data structures holding information related to HW and the OS. On Manjaro, it holds information for block devices, busses (such as USB, HID, PCI, and CPU), devices, firmware, the kernel, and so on.
/tmp
The directory for temporary files. These are files that will never be required after reboot. Examples are temporary data from your browser and temporary results from running software. On Arch and most Linux distributions, a pseudo-FS called tmpfs is used in it, which is flushed upon boot.
/usr
This is usually the location of all directories for executables, libraries, binaries, and installation files related to and installed by users. In the distant past, the /usr/bin directory was on a separate HDD, which was expensive, small, and contained all critical binaries for running the system. When placed there, the most frequently executed binaries were fast to reach and execute. Back then, many other infrequently used directories were on a slower disk. Nowadays, disks are big and fast, and such separation is unnecessary. As a result, Debian and Arch Linux merged the usr directories with the system directories, and Debian called the operation UsrMerge. Currently, many Arch and Debian derivatives use the same approach. This is why bin links to /usr/bin, lib links to /usr/lib, lib64 links to /usr/lib, and sbin links to /usr/bin.
/var
This last directory holds any constantly changing variable data files such as logs, temporary data for games, mail, libraries, and caches. It is not cleaned automatically like /tmp, and inspecting it is often the best way to check what happened on a given system during the latest runs. As we saw in Chapter 8, here are the pacman and pamac caches. It also contains the journalctl logs, which we will explore in Chapter 13.
Next article: 10.3 Backups, Tools, Rsync, And Recovery.
* * * * *
You can subscribe for news, discounts, and giveaways HERE. Triple Helix Guarantees 100% privacy and will never provide your data to third parties. We keep the right to inform you on some of the news for our open-source projects, which will be rare. You can unsubscribe at any moment.
You can also follow me for such news on LinkedIn, where the giveaways will take place. I share development news, guides, and helpful content.
All rights reserved. Parts of this free content are allowed to be cited only when the official link to this article is provided as a source of the information, the author’s name is mentioned, as well as the publisher and the book name. Example: “Cited from the article <insert_link> by Atanas Georgiev Rusev, as part of the Manjaro Linux User Guide book, by PACKT publishing. All rights reserved”.