Skip to main content

Understanding The Directory Structure In Linux

When a Linux operating system is installed, a specific directory structure is created by default, defining the hierarchy of files and directories in the system. Understanding this structure is vital for effectively managing and operating the system.

/ (Root)
├── bin
├── boot
├── dev
├── etc
├── home
│ ├── user1
│ └── user2
├── lib
├── media
├── mnt
├── opt
├── proc
├── root
├── run
├── sbin
├── srv
├── sys
├── tmp
├── usr
│ ├── bin
│ ├── include
│ ├── lib
│ ├── local
│ ├── sbin
│ └── share
└── var
├── cache
├── lib
├── local
├── lock
├── log
├── mail
├── opt
├── run
├── spool
└── tmp

In Linux, you can navigate to the root directory from any other directory by using the cd (change directory) command followed by a forward slash /. Here is the command:

cd /

The forward slash / represents the root directory in a Unix-like operating system like Linux. So, cd / will change your present working directory to the root directory. You can confirm this by using the pwd (print working directory) command, which should return /.

In Unix-like operating systems, ~ is a shorthand or alias for the home directory of the current logged-in user. So, when you use cd ~, it changes the current directory to the home directory of the user.

cd ~

For example, if you're logged in as a user named username, running cd ~ would take you to the home directory of username, usually located at /home/username in the filesystem. If you are the root user, cd ~ would take you to /root, which is the home directory for the root user.

Various Directories And Their Purpose

Let's delve into the key elements of the Linux directory structure and the significance of each default directory. These directories might vary based on the Linux distribution you are working on but most of them would be common across all Linux distros.

/Root Directory: Every single file and directory starts from the root directory. It is the starting point of the file system hierarchy and holds other directories and subdirectories. Only root user has write privilege under this directory.
/binContains executable binary files, or commands that users typically run (e.g., ls, ping, grep, cp). Essential for both the system and the user.
/sbinContains system binaries. Holds binary executables that only the root user or system administrator would need to use for system maintenance purposes (e.g., ifconfig, reboot, fdisk).
/etcDesignated for system-wide configuration files. Holds important configuration files required by all system applications. Also includes start-up and shutdown shell scripts.
/homePersonal space for users. Each user on the system will have a directory here, containing personal files, directories, and personal configuration files.
/varContains variable data like system logging files, mail and printer spool directories, and transient and temporary files. Frequently utilized by various system programs/processes.
/tmpHolds temporary files used by system applications. Accessible to every user. Files in this directory are deleted every time the system restarts.
/usrAlso known as Unix System Resources. Contains shareable, read-only data. Holds user binaries, libraries, documentation, and source code for second level programs. Similar to the /bin directory.
/bootContains files needed to boot the system (e.g., GRUB boot loader's files, kernels, and other essential boot-up files).
/libContains kernel modules and shared library images required to boot the system and run the commands in the root file system.
/devContains device files. Linux treats everything like files, including devices. These files represent physical devices like hard drives and I/O devices.
/procContains information about system processes. This is a pseudo-filesystem containing information about running processes with a directory for each PID (Process Identification Number).
/optFor the installation of add-on software packages. Traditionally contains third-party software.
/mntMount point for temporarily mounted file systems. Administrators often mount other (temporary) file systems here.
/mediaMount point for removable devices like USB sticks, CD-ROMs, or SD cards.
/rootHome directory of the root user (superuser). Not the same as the root (/) directory. Usually located in the / directory and its actual location is /root.
/srvContains data for services provided by the system. The naming and structuring within /srv is left to the discretion of the system administrator.

Understanding these directories and their purposes can significantly enhance your competency in managing Linux systems, from performing basic operations to troubleshooting issues effectively.

TypeScript Course Instructor Image
TypeScript Course Instructor Image

Time To Transition From JavaScript To TypeScript

Level Up Your TypeScript And Object Oriented Programming Skills. The only complete TypeScript course on the marketplace you building TypeScript apps like a PRO.


What Can You Do Next 🙏😊

If you liked the article, consider subscribing to Cloudaffle, my YouTube Channel, where I keep posting in-depth tutorials and all edutainment stuff for ssoftware developers.

YouTube @cloudaffle