The Wayback Machine - https://web.archive.org/web/20250304082056/https://www.geeksforgeeks.org/linux-directory-structure/
Open In App

Linux Directory Structure

Last Updated : 08 Jun, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

Prerequisite: Linux File Hierarchy Structure

In Linux/Unix operating system everything is a file even directories are files, files are files, and devices like mouse, keyboard, printer, etc are also files. Here we are going to see the Directory Structure in Linux.

Types of files in the Linux system. 

  1.  General Files – It is also called ordinary files. It may be an image, video, program, or simple text file. These types of files can be in ASCII or Binary format. It is the most commonly used file in the Linux system.
  2. Directory Files – These types of files are a warehouse for other file types. It may be a directory file within a directory (subdirectory).
  3. Device Files – In a Windows-like operating system, devices like CD-ROM, and hard drives are represented as drive letters like F: G: H whereas in the Linux system devices are represented as files. As for example, /dev/sda1, /dev/sda2, and so on.

We know that in a Windows-like operating system, files are stored in different folders on different data drives like C: D: E: whereas in the Linux/Unix operating system files are stored in a tree-like structure starting with the root directory as shown in the below diagram. 

data storage in Linux/Unix operating systems

The Linux/Unix file system hierarchy base begins at the root and everything starts with the root directory. 

These are the common top-level directories associated with the root directory:

Directories Description
 /bin  binary or executable programs.
/etc system configuration files.
/home home directory. It is the default current directory.
/opt optional or third-party software.
/tmp temporary space, typically cleared on reboot.
/usr  User related programs.
/var  log files.

Some other directories in the Linux system:

Directories  Description
/boot

It contains all the boot-related information files and folders such as conf, grub, etc.

/dev

It is the location of the device files such as dev/sda1, dev/sda2, etc.

/lib

It contains kernel modules and a shared library.

/lost+found

It is used to find recovered bits of corrupted files.

/media

It contains subdirectories where removal media devices are inserted.

/mnt

It contains temporary mount directories for mounting the file system.

/proc

It is a virtual and pseudo-file system to contains info about the running processes with a specific process ID or PID.

/run

It stores volatile runtime data.

/sbin

binary executable programs for an administrator.

/srv 

It contains server-specific and server-related files.

/sys

It is a virtual file system for modern Linux distributions to store and allows modification of the devices connected to the system.

Exploring directories and their usability:

We know that Linux is a very complex system that requires an efficient way to start, stop, maintain and reboot a system, unlike Windows operating system. In the Linux system some well-defined configuration files, binaries, main pages information files are available for every process. 

Linux Kernel File:

  • /boot/vmlinux – The Linux kernel file.

Device Files:

  • /dev/hda – Device file for the first IDE HDD.
  • /dev/hdc – A pseudo-device that output garbage output is redirected to /dev/null.

System Configuration Files:

Configuration Files Description
/etc/bashrc It is used by bash shell that contains system defaults and aliases.
/etc/crontab A shell script to run specified commands on a predefined time interval.
/etc/exports  It contains information on the file system available on the network.
/etc/fstab Information of the Disk Drive and their mount point.
/etc/group  It is a text file to define Information of Security Group.
/etc/grub.conf It is the grub bootloader configuration file.
/etc/init.d  Service startup Script.
/etc/lilo.conf   It contains lilo bootloader configuration file.
/etc/hosts Information of IP and corresponding hostnames
/etc/hosts.allow It contains a list of hosts allowed accessing services on the local machine.
/etc/host.deny  List of hosts denied accessing services on the local machine.
/etc/inittab  INIT process and their interaction at the various run levels.
/etc/issue Allows editing the pre-login message.
/etc/modules.conf It contains the configuration files for the system modules.
/etc/motd  It contains the message of the day.
/etc/mtab  Currently mounted blocks information.
/etc/passwd   It contains username, password of the system, users in a shadow file.
/etc/printcap   It contains printer Information.
/etc/profile  Bash shell defaults.
/etc/profile.d It contains other scripts like application scripts, executed after login.
/etc/rc.d  It avoids script duplication.
/etc/rc.d/init.d  Run Level Initialisation Script.
/etc/resolv.conf DNS being used by System.
/etc/security  It contains the name of terminals where root login is possible.
/etc/skel Script that initiates new user home directory.
/etc/termcap An ASCII file that defines the behavior of different types of the terminal.
/etc/X11 Directory tree contains all the conf files for the X-window System.

User Related Files:

User Related Files Descriptions
/usr/bin  It contains most of the executable files.
/usr/bin/X11  Symbolic link of /usr/bin.
/usr/include  It contains standard files used by C program.
/usr/share It contains architecture independent shareable text files.
/usr/lib  It contains object files and libraries.
/usr/sbin It contains commands for Super User, for System Administration.

Virtual and Pseudo Process Related Files:

Virtual and Pseudo Process Related Files Descriptions
/proc/cpuinfo CPU Information
/proc/filesystems It keeps useful info about the processes that are currently running.
/proc/interrupts  it keeps the information about the number of interrupts per IRQ.
/proc/ioports Contains all the Input and Output addresses used by devices on the server
/proc/meminfo It reports the memory usage information.
/proc/modules Currently using kernel module.
/proc/mount Mounted File-system Information.
/proc/stat It displays the detailed statistics of the current system.
/proc/swaps  It contains swap file information.

Version Information File:

  • /version – It displays the Linux version information.

Log Files:

Log Files Descriptions
/var/log/lastlog  It stores user’s last login info.
/var/log/messages  It has all the global system messages
/var/log/wtmp It keeps a history of login and logout information.

To check the Linux directories, open the terminal and execute sudo -s followed by system password to give root privilege. Then after changing the current home directory to the root directory and check the list of all available directories in the base directory as shown below. 

 Linux directories

 Linux directories

Conclusion

If we understand the Linux directory’s structure correctly, it would be so easy to effectively navigate and manage our filesystem, locate important configuration files, and access system information. One must know that the directory structure and specific file mentioned in this article are based on standard Linux conventions. We must consider that the different Linux distributions may have variations in the directory structure and specific file locations, but overall concept and organization remain similar.


Master DevOps and also get 90% Course fee refund on completing 90% course in 90 days! Take the Three 90 Challenge today.

The most sought-after Three 90 challenge has started and this is your chance to upskill and get 90% refund. What more motivation do you need? Start the challenge right away!


Next Article
Article Tags :

Similar Reads

Shell Script to Delete a File from Every Directory Above the Present Working Directory
In this article, we will discuss how to delete a file from every directory above the parent working directory using shell script in Linux. To delete a file from a directory we use the rm command in Linux/UNIX. Syntax: rm [OPTION]... [FILE]... Using shell script, we have to delete the input file from every directory above the present working direct
2 min read
DotDotPwn - Directory Traversal Fuzzer Tool in Linux
Directories in the Web-based application hold various information about the functionalities of the website. Some directories can be common or usual, but some of the directories are attractive or important directories that can contain some important information. Like /etc/passwd can contain the information about the Linux server. Traversing this dir
4 min read
OpenDoor - OWASP Directory Access Scanner in Kali Linux
Brute-Forcing is an automated process through which Usernames, Passwords can be detected by querying the possible credentials on the target domain login pages. We can also brute-force hidden files and directories on the target server by specifying the possible word-list which contains the phrases that will be tested on the domain. This process save
3 min read
How to Count Files in Directory Recursively in Linux
When exploring directories on your server, you may have come across folders with a large number of files in them. You might wish to know how many files exist in a certain directory or across many directories at times. To put it another way, you wish to count the number of files saved in a directory on your system. In this article, we are going to s
5 min read
Copy and Create Destination Directory if it Does Not Exist in Linux
A directory is a file system location for storing and organizing files. A Linux system has many directories, and users can create their own directories. Copying and creating a directory are useful operations for Linux users. To create a new directory, use the command: mkdir new_directory. The 'm' stands for 'modify.' The name of the new directory m
6 min read
Find and Replace with sed in Directory and Sub Directories in Linux
sed stands for stream editor. It is a basic utility command in Linux that has basic functionality like inserting, deleting, finding, replacing, and searching text strings in a file. But sed is most commonly used for its substitution function i.e find and replace. Syntaxsed OPTIONS... [script] [input_file] e.g. sed "s/abc/ABC/g" abc.txt Consider th
4 min read
mindepth and maxdepth in Linux find() command for limiting search to a specific directory.
How to limit search a specified directory in Linux? There is a command in Linux to search for files in a directory hierarchy known as 'find'. It searches the directory tree rooted at each given starting-point by evaluating the given expression from left to right, according to the rules of precedence, until the outcome is known (the left-hand side i
5 min read
How to Remove Directory in Linux
In Linux, directories are used to organize files and other directories into a hierarchical structure. Just like folders in Windows, directories in Linux can contain files, other directories, and links. Removing directories in Linux is a common task that you might need to perform as you manage files and organize your file system.When you want to rem
5 min read
How to Copy a Directory in Linux
There is this famous quote for Linux by Jamie Zawinski that goes like this "Linux is only free if your time has no value." Certainly, that's true as people start using Linux they have to learn more about it, and when encountering it we have to solve it by ourselves, and that way we learn more about Linux. In this article, we are going to learn how
5 min read
How to Fix - Unable to Lock the Administration Directory – Kali Linux
Kali Linux is among the most famous OS for ethical hacking and pentesting. It contains all the necessary tools for pentesting and ethical hacking. Using Kali is not easy and every user has once encountered errors. In this article, we will see how to solve this particular problem using Kali Linux. What is Unable to lock the administration directory
5 min read