DEV Community

Cover image for Linux file system
jck
jck

Posted on

Linux file system

Introduction to Linux Directory Structure

Most Linux users have seen the root directory (/), but not everyone understands the purpose of the various directories it contains. For a user coming from Windows, exploring the file manager in Linux might seem familiar at first: you'll find folders like "Documents", "Downloads", "Pictures", and "Videos". However, this familiarity quickly fades when you start looking for directories like "Program Files" or the C drive, which are ubiquitous in Windows.

Different Evolution of Windows and Linux

To understand why Linux is structured differently, it's helpful to look back at the history of operating systems.

MS-DOS and the Early Days of Windows

  • MS-DOS: Initially, there was MS-DOS, a command-line operating system. You could run programs, games, and software like WordPerfect on it. MS-DOS used letters to designate drives: A and B for floppy disks, and C for the primary hard drive.

  • Windows: Windows was layered on top of MS-DOS. To start Windows, you had to type win in the MS-DOS command-line interface. Over time, Microsoft made Windows increasingly independent of MS-DOS, until it could boot without it.

Linux Directory Structure

Linux, on the other hand, follows UNIX traditions, which explains several fundamental differences from Windows:

  • Use of the Slash (/) : Unlike Windows, which uses the backslash (\), Linux uses the slash to separate directories.

  • Case Sensitivity: Linux is case-sensitive, meaning that "file", "File", and "FILE" are considered different files.

  • No "Program Files" Directory: In Linux, applications are not all installed in a centralized directory like "Program Files". Instead, they are distributed across various directories based on their nature and usage.

Main Directories in Linux

The structure of directories in Linux is defined by the Filesystem Hierarchy Standard (FHS), although not all distributions adhere strictly to this standard. Here is a detailed description of the main directories:

/bin
Contains essential binary executables needed by all users. Examples include commands like ls, cat, cp, and mv.

/sbin
Contains system binaries, used mainly by the system administrator for maintenance and repair tasks. Examples include ifconfig and reboot.

/boot
Contains files needed for the system to boot, such as the bootloader (GRUB) and the Linux kernel.

/dev
Contains device files. In Linux, everything is considered a file, including hardware devices. For example, /dev/sda represents the first hard drive.

/etc
Contains system configuration files. Examples include network service configurations and package manager source lists.

/home
The personal directory for users, where each user has their own subdirectory to store personal files and settings.

/lib, /lib32, /lib64
Contain shared libraries needed by the binaries in /bin and /sbin.

/media and /mnt
Mount points for removable devices. /media is often used for automatic mounting, while /mnt is used for manual mounts.

/opt
Contains optional software, often manually installed or from third-party vendors.

/proc
A virtual filesystem containing information about running processes and system resources. For example, /proc/cpuinfo contains information about the CPU.

/root
The personal directory for the root user, the system administrator.

/run
A temporary filesystem in RAM, used to store runtime information for processes started early in the boot process.

/snap
Contains Snap packages, a self-contained package format used primarily by Ubuntu.

/srv
Contains data for services, such as files for a web or FTP server.

/sys
An interface with the kernel for information about hardware and devices. For example, information about connected USB devices.

/tmp
A temporary directory for files used during a session. Files in /tmp are usually deleted upon reboot.

/usr
Contains user applications and libraries. For example, /usr/bin contains user binary executables.

/var
Contains variable files, such as system logs, databases, and print queues.

Conclusion

While the directory structure in Linux may seem complex at first, it allows for efficient management of resources and applications. Package managers, like apt for Debian/Ubuntu or yum for Fedora, facilitate the installation, updating, and removal of software by following these conventions.

If you found this information useful, feel free to share it and subscribe for more content.

Top comments (0)