The directory structure of Linux explained
The directory structure of Linux is organized in a hierarchical tree-like format, with the root directory (/
) at the base. Each directory serves a specific purpose and contains specific types of files. Here's an overview of the common directories found in a typical Linux file system and their significance, along with some examples:
Root Directory (/
)
The root directory is the top-level directory in the Linux file system. All other directories and files are contained within this directory.
/bin
- Purpose: Contains essential binary executables for system operation.
- Significance: Programs in
/bin
are necessary for booting and repairing a system. - Example:
/bin/ls
(list directory contents),/bin/cp
(copy files),/bin/mkdir
(create directories).
/boot
- Purpose: Contains files necessary for the booting process.
- Significance: Includes the Linux kernel and boot loader configuration files.
- Example:
/boot/vmlinuz
(compressed Linux kernel image),/boot/grub/grub.cfg
(GRUB boot loader configuration).
/dev
- Purpose: Contains device files.
- Significance: Provides an interface to hardware devices (e.g., disks, terminals) through special files.
- Example:
/dev/sda1
(first partition on the first SCSI disk),/dev/tty
(current terminal).
/etc
- Purpose: Contains system-wide configuration files.
- Significance: Config files for system services and applications are stored here.
- Example:
/etc/fstab
(file system mount table),/etc/passwd
(user account information),/etc/ssh/sshd_config
(SSH server configuration).
/home
- Purpose: Contains personal directories for users.
- Significance: Each user has a subdirectory in
/home
where personal files and settings are stored. - Example:
/home/user1
(home directory for user1),/home/user2
(home directory for user2).
/lib
- Purpose: Contains essential shared libraries and kernel modules.
- Significance: Libraries required by the binaries in
/bin
and/sbin
. - Example:
/lib/libc.so.6
(GNU C Library),/lib/modules
(kernel modules).
/media
- Purpose: Mount points for removable media.
- Significance: Used for automatically mounting external devices like USB drives and CDs.
- Example:
/media/cdrom
(mount point for CD-ROM),/media/usb
(mount point for USB drive).
/mnt
- Purpose: Temporarily mounted file systems.
- Significance: Used for manually mounting external devices.
- Example:
/mnt/backup
(temporary mount point for a backup drive).
/opt
- Purpose: Optional application software packages.
- Significance: Used for installing additional software.
- Example:
/opt/google/chrome
(Google Chrome installation).
/proc
- Purpose: Contains virtual files that provide information about the system and running processes.
- Significance: Used for system and process information.
- Example:
/proc/cpuinfo
(CPU information),/proc/meminfo
(memory information).
/root
- Purpose: Home directory for the root user.
- Significance: The root user's personal files and settings are stored here.
- Example:
/root/.bashrc
(bash configuration for root).
/run
- Purpose: Stores transient files needed by system processes.
- Significance: Contains runtime data, typically created at system boot and destroyed at shutdown.
- Example:
/run/lock
(lock files),/run/user
(runtime data for user sessions).
/sbin
- Purpose: Contains essential system binaries.
- Significance: Programs in
/sbin
are intended for use by the superuser (root). - Example:
/sbin/ifconfig
(network interface configuration),/sbin/reboot
(reboot the system).
/srv
- Purpose: Contains data for services provided by the system.
- Significance: Used by servers to store data served to users.
- Example:
/srv/ftp
(files for FTP server),/srv/www
(web server files).
/tmp
- Purpose: Contains temporary files.
- Significance: Used by applications to store transient data.
- Example:
/tmp/sess_abcdef
(temporary session file).
/usr
- Purpose: Contains user programs and data.
- Significance: A secondary hierarchy for read-only data, typically large applications and utilities.
- Example:
/usr/bin
(user binaries),/usr/lib
(user libraries),/usr/share
(shared data).
/var
- Purpose: Contains variable data files.
- Significance: Files that are expected to grow in size, such as logs and spool files.
- Example:
/var/log
(log files),/var/spool
(spooled files like mail and print jobs),/var/www
(web server files).
Examples of Directory Usage
-
Checking Disk Usage:
du -h /var/log
This command checks the disk usage of log files stored in
/var/log
. -
Accessing Configuration Files:
cat /etc/fstab
This command displays the file system table configuration in
/etc/fstab
. -
Viewing System Information:
cat /proc/cpuinfo
This command displays CPU information stored in
/proc/cpuinfo
.