In this article, we explain Linux directory structure and file system for beginners to Linux. First we provide an overview of the file system hierarchy and then explain briefly the high level directories. Lastly, we give examples of Linux commands that can be used to list Linux directory structure in a visual format.
For those of you who come from the Windows world and got used the drive letters such as C:\, Linux directory structure might seem odd with cryptic namings. However, Linux has a very clear and neat design, including the file system hierarchy.
To explain the major differences upfront, in Linux there is only one root level directory that is denoted with a forward slash and and directories are separated again with forward slashes rather than the backward slash being used in the Windows operating system. Also note that, in Linux the term “directory” is used for what is known as a folder in the Windows world.
UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.Dennis Ritchie
Read more educational and inspirational cyber quotes at our page 100+ Best Cyber Security & Hacker Quotes.
File System Hierarchy
Linux directory structure is like a tree that begins with a top level directory called “Root”. Rest of the directories brach off this “Root” directory denoted with the forward slash sign. A high level overview of this file system hierarchy is illustrated in Figure 1.
Next, we will explain the meaning and purpose of each of these common directories used in Linux.
Common Directories in Linux
/ – The Root Directory
- The single, top level directory in Linux.
- Every other directory of the Linux file system branches off from this directory.
- Note that,
/should not be confused with the
/root, that is the home directory for the
/home – User Directories
- User home directories are listed under this directory.
/home, a directory like
/home/usernameexists for each user.
- Note that, the home directory is
/rootfor the root user rather than
/root – Home Directory for Root
- Home directory for the
- As explained above, this should not be confused with the top level directory, that is the
/bin – User Binaries
- Binaries and executable files for the users reside at this directory.
- These are usually the binary files common for all users.
- User specific binary files are kept at the
/sbin – System Binaries
- Binaries files related to the system administration are stored at this directory.
- User specific system binary files are kept at the
/usr – User Programs
- User related programs are kept on this directory.
- Similar to the
/homedirectory, a subdirectory structure exists for each user, such as
/opt – Optional Applications
- Optional and third party software live at this directory.
- These are usually the applications that are not bundled with the operating system.
/etc – Configuration Files
- System configuration files that control how the operating system or applications behave.
- Files in this directory usually have a naming convention ending with .conf such as
/tmp – Temporary Files
- Temporary files are stored at this directory.
- Typically this directory is emptied each time the operating system reboots.
/var – Variable Files
- Variable data and files are stored at this directory.
- Content of such files can grow or reset as the system runs.
- Typically log files that changes over time reside at
/dev – Device Files
- This directory contains device files controlled by the operating system.
- Devices could include anything attached to the system such monitors, keyboards etc.
/sys – System Files
- Configuration files and data related to devices known to the Linux kernel live at this directory.
/proc – Process Information
- This directory contains information related to the running processes in the system.
- This is a pseudo file system that consists of subdirectories for each process.
- The naming convention for the subdirectories is like
/proc/pid(pid: Process Id).
/boot – Boot Loader Files
- Files related to the booting the operating system reside at this directory.
grubfiles etc. are located here.
/lib – System Libraries
- System library files are stored at this directory.
- There could be an addition directory, such as
/lib64for 64 bit library files.
/srv – Service Data
- Data relating to the services provided by the system are typically stored at this directory.
- Provided services could have specific subdirectories under this directory, such as
/mnt – Mount Directory
- External file systems are mounted on this directory.
- Depending on the Linux distribution,
/cdromdirectories might exist additionally.
/media – Removable Devices
- Typically removable media are mounted on this directory.
- This could differ depending on the Linux distribution.
/cdrom – Mount Directory (CD-ROMs)
- CD-ROMs are typically mounted on this directory.
- This could differ depending on the Linux distribution.
These are almost all the main directories you may come across on a variety of Linux distributions. Next, let’s explore how we can list directories in Linux in a tree-like format.
Linux Commands for Directory Listing
ls command is used to list information about the FILE(s) (the current directory by default). Basic usage for this command is:
ls [OPTION] ... [FILE] ... For the most often used parameters,
-a can be used to list all entries (including the hidden ones that start with
-l can be added to list with more details, such as file permissions, file size etc.
To list all the subdirectories recursively,
--recursive options could be used with the
$ ls -R
However, the output of this command is hard to track since it is not in a tree-like format.
To generate recursive directory listing in tree-like visualization,
tree command can be used with
-d option. Additionally,
-L option can be used to specify the maximum display depth of the directory tree.
For instance, to display all the directories with 1 level of maximum depth, the following command can be used.
$ tree -d -L 1
The output of the
tree -d -L 1 command in Kali Linux at the root directory level is shown in Figure 2.
To learn more on Linux, you could also read our article Basic Linux Commands for Beginners or visit Linux Resources Page.