Getting started with Linux File Hierarchy Structure
The Linux File Hierarchy Structure or the Filesystem Hierarchy Standard (FHS) defines the directory structure and directory contents in Unix-like operating systems. It is maintained by the Linux Foundation.
What is Tree in Linux?
Tree is a recursive directory listing program that produces a depth-indented listing of files. With no arguments, tree lists the files in the current directory. When directory arguments are given, tree lists all the files or directories found in the given directories each in turn. Upon completion of listing all files and directories found, tree returns the total number of files and directories listed.
If you are using Debian / Mint / Ubuntu Linux, type the following apt-get command to install the tree command :
Basic tree command:
$ sudo apt install tree
$ tree
Display Contents of a Specific Directory
$ tree -a [DirectoryName/Path]
Display Hidden Files along with Other Files Using Tree
tree -a
File System Hierarchy:
/bin
/boot
/dev
/etc
/home
/lib
/media
/mnt
/opt
/root
/sbin
/proc
/srv
/sys
/tmp
/usr
/var
Directories:
Let’s begin the root directory “/”:
/
Linux file-system structure is hierarchical, all files are stored on the disk under one main directory, / (root). The directory has been further subdivided into directories like /usr, /var, /mnt, /boot, etc. as shown in the structure above.
This is the entry point of all directories and is described as a forward slash, which is actually the home of the Operating System. Everything is in it. Not every user has read and write privileges to this directory; only the administrators or allowed users of the operating systems can have access to such privileges.
We are switching to root directory using / command as shown below:
Different mounts in file system hierarchy
/bin - This is the directory that has all the binary files of some important programs on the operating system.This directory holds the data about the most used commands such as mkdir , ls, rm. According to the Linux Filesystem Standards, this directory cannot have subdirectories.
/boot
This is the directory that handles the ignition of the Linux Operating System. First of all, you don’t need to modify anything in this directory, otherwise, you can’t alter anything in it unless you have administrator’s rights. You should stay away from doing anything in this directory, or else it will be a huge mess to set it up again.
/dev
This directory holds the files of the devices like a USB Device or a Hard Drive. Most of the files are either created on the boot time or when a device is attached.
- /etc -This directory mostly contains the static program local files that affect all users. This directory mostly contains files related to the configuration.
/home - This is the directory where most of the user’s personal data is placed.
/proc -This is the directory with the pseudo files. The pseudo files contain information about the processes.
/sys - This directory is always created during boot time, so it is a virtual directory like /dev, and it is the directory when you want to communicate to the Kernal. It also holds information related to the connected devices.
/tmp - This is a temporary directory and holds the temporary files of the applications running on the system.
/usr -This directory contains the applications installed and used by the user. It is also known as the “UNIX System Resources”. It also has its own /bin, /sbin, and /lib directory, which is different from the superuser’s /bin, /sbin, and /lib directories.
/var -This is a variable directory that contains the files and folders whose size is expected to increase with the passage of time and the system’s usage.
-
/lib -These are the folders where libraries are stored. Libraries are some files that are needed by any application to perform several tasks or functions. For example, these libraries may be needed by the binary files in the /bin directory.
/media
This directory is similar to /mnt. The difference is that, in /mnt, mount points are manually mounted while in /media, mount points are automatically mounted. This as well depends on the Linux distribution.
/mnt
This directory can be used as a directory where users can temporarily mount file-systems
/opt
This is the optional folder. It is the directory where manually installed software by vendors is placed.
/sbin
This directory is just like the /bin directory, but this is used by the superuser, and that’s why “s” is used before bin.
/srv
This directory stores the data of the services running on the system.
Conclusion
In this way we have understood what is the file structure and hierarchy in linux operating system. Stay tuned to learn more such topics.