Everything You Need to Know About Linux Root

Learning rudimentary knowledge gives mind-blowing epiphanies. Don’t you agree? In this tutorial, we are going to dissect the root directory of the Raspberry Pi – a must-know for aspiring Linux professionals.

Introduction

The Raspberry Pi OS, formerly known as Raspbian, is a Debian-based Linux operating system. It follows the Filesystem Hierarchy Standard (FHS) that the Linux Foundation maintains.

Moreover, the FHS determines the structure and purpose of all the directories inside Linux distributions. That is why learning its every nook and cranny opens a lot of possibilities for anyone’s career.

The Linux Root Directory

The basic unit of the FHS is the root directory. The root directory contains all the files and directories on a Linux system and is designated by a ‘/’ symbol. From users to installed software, everything comes from the root. So knowing how to look around will definitely make your Linux experience better.

There are two ways you can access the root directory: One is using GUI and another using CLI.

Accessing the Linux Root Directory

Using GUI (Graphical User Interface)

1. First, open File Explorer by clicking the folder icon on the top right corner of your Menu Bar.

Figure 1: File Explorer

2. Then, choose Filesystem Root above the File Tree on the right.

Figure 2: The Root Directory using GUI

Using CLI (Command Line Interface)

1. First, enter CLI by pressing CTRL + ALT + T.

2. Then, enter the command below:

cd /

3. You can use pwd to check. Furthermore, you can view the content of the root directory using ls.

Figure 3: The Root Directory using CLI

The Root Contents

/bin – Binaries

The binaries folder contains the executable files of Linux shell commands. Inside this directory, you can find ls.exe, cd.exe, pwd.exe, rm.exe, and etc. It is called binaries because most programs here are in binary format.

/boot – Boot files

The boot files folder contains the kernel, the boot image, and the boot loader. The kernel is an OS subcomponent that makes computer hardware work. The boot image is an initial file that is mounted to install the kernel. Lastly, the boot loader loads the kernel to start the computer.

/dev – Device files

The device files folder contains files that represent hardware. For instance, /dev/usb represents your USB, /dev/dsp for your speaker, and /dev/hda1 and /dev/hda2 acts as stand-in files for the first and second partition of your computer.

There are also special files inside the directory. Some of them are the following:

  • /dev/null: can delete any file
  • /dev/zero: contains an infinite set of zeroes
  • /dev/random: contains an infinite set of random values

/etc – Configuration files

The configuration files folder contains the settings of your system. This is where change happens when you fiddle with raspi-config. Some examples of its contents are hostnames, passwords, and networking files.

/home – User data

The user data folder contains personal directories for all the users of the system. It contains user preferences and user-specific settings. Furthermore, all the files on your account go to your particular directory inside /home.

/lib – Libraries

The libraries folder contains all code dependencies used by executable binaries. No need to dive down this yet. All you need to know is that the /lib directory holds the libraries needed by the binaries in /bin and /sbin directories.

/media – Media

The media folder contains the files for mounting removable devices such as a flash drive or an SD card. For instance, when you insert a flash drive, a directory is automatically created under the /media directory. Inside that directory will be the files and folders of your flash drive.

/mnt – Mount

The mount folder is similar to /media but instead of removable devices, /mnt is used to mount a whole filesystem.

/opt – Optional software

The optional software folder contains all the files of third-party applications. Third-party applications are software that is not included from the distribution’s repository.

When you install a third-party app, the software installation and storage files go to /opt while the executable binary file goes to /bin. The binaries folder allows the software to be used by the users.

/proc – Process Files

The process files folder contains the real-time data of the currently running processes and kernel parameters on the system. You can get useful system information from this directory using system tools. For instance, if you want to view real-time information about the ARM Cortex-A72 processor of the Raspberry Pi 4, you simply go to /proc/cpuinfo. Additionally, you can check memory usage by opening the file /proc/meminfo.

/root – Root User

The root user folder is simply the home directory of the root user. Remember su and sudo? This what you access when you’re using these commands.

/sbin – System binaries

The system binaries folder contains the executable binaries that can only be run by the root user or the superuser. The name kind of gives it away, to be honest. It’s a conjunction of superuser and /bin.

/srv – Service data

The service data folder contains the data for the services the system uses. If you’re planning to use the Raspberry Pi as a single-purpose device, you may want to put the main program data here.

/tmp – Temporary files

The temporary files folder contains exactly what is named for – temporary files. Almost all applications use temporary files to either speed things up or temporarily remember user preferences. The files inside this folder get deleted when you reboot.

/usr – User binaries and program data

The user binaries and program data folder contain all data for system programs. For instance:

  • ‘/usr/bin’ contains basic user commands
  • ‘/usr/sbin’ contains additional commands for the administrator
  • ‘/usr/lib’ contains the system libraries
  • ‘/usr/share’ contains documentation or common to all libraries, for example ‘/usr/share/man’ contains the text of the manpage

/var – Variable data

The variable data folder contains runtime information on programs. Some examples are caches, system logs, and user tracking files. Additionally, unlike /tmp, the files here are not cleared every boot, which is especially helpful if you want to check things like login history. You can just go to /var/log/wtmp.

Well, that’s about it for the basic Linux directory structure. See you next time and keep circuit rockin’!

If you want to learn more about linux here are some articles I recommend: