DEV Community

Darshan Rathod
Darshan Rathod

Posted on

Linux File System Explained: Everything You Need to Know

Linux is a robust and versatile operating system that manages data through a well-organized file system. Gaining a solid understanding of the Linux file system is essential for users at all levels, as it enhances navigation, streamlines system administration, and aids in troubleshooting. This guide delves into the Linux file system, covering its structure, core directories, and fundamental file management practices.

What is the Linux File System?

The Linux file system follows a hierarchical directory structure where everything—directories, devices, and even hardware components—is treated as a file. Unlike Windows, which organizes storage using drive letters like C: and D:, Linux operates under a unified structure with a single root directory (/) that encompasses all files and directories.

Linux File System Hierarchy

The Linux file system follows the Filesystem Hierarchy Standard (FHS), which defines a consistent structure for directories and files. Below is an overview of essential directories with examples:

1. / (Root Directory)

The top-level directory from which all other directories branch out.

Only the root user has full access to modify critical system files.

Example:

ls /
Enter fullscreen mode Exit fullscreen mode

Lists all top-level directories.

2. /bin (Binary Executables)

Contains essential system binaries (commands) like ls, cp, mv, rm, and cat.

Example:

ls /bin

Enter fullscreen mode Exit fullscreen mode

Lists all essential system binaries.

3. /boot (Boot Loader Files)

Stores files needed for booting the system, including the Linux kernel (vmlinuz), bootloader configuration, and initial RAM disk (initrd).

Example:

ls /boot
Enter fullscreen mode Exit fullscreen mode

Displays all boot-related files.

4. /dev (Device Files)

Contains files representing hardware devices (e.g., /dev/sda for the first hard disk, /dev/tty for terminals).

Example:

ls /dev | grep sda
Enter fullscreen mode Exit fullscreen mode

Lists available storage devices.

5. /etc (Configuration Files)

Stores system-wide configuration files and scripts.

Example:

cat /etc/passwd
Enter fullscreen mode Exit fullscreen mode

Displays system user account details.

6. /home (User Home Directories)

Contains personal directories for users (e.g., /home/user1, /home/user2).

Example:

ls /home
Enter fullscreen mode Exit fullscreen mode

Lists all user directories.

7. /lib & /lib64 (Shared Libraries)

Stores essential shared libraries required by system programs.

Example:

ls /lib | grep libc
Enter fullscreen mode Exit fullscreen mode

Lists shared C library files.

8. /media & /mnt (Mount Points)

/media: Used for mounting external devices like USB drives and CDs.

/mnt: Temporary mount point for manual mounting of filesystems.

Example:

mount /dev/sdb1 /mnt
ls /mnt
Enter fullscreen mode Exit fullscreen mode

This mounts an external drive and lists its contents.

9. /opt (Optional Software)

Contains software installed by third-party vendors.

Example:

ls /opt
Enter fullscreen mode Exit fullscreen mode

Lists installed optional software.

10. /proc (Process Information)

Virtual filesystem that provides information about running processes and system resources.

Example:

cat /proc/cpuinfo

Enter fullscreen mode Exit fullscreen mode

Displays CPU details.

11. /root (Root User’s Home Directory)

Home directory for the root user.

Example:

ls /root
Enter fullscreen mode Exit fullscreen mode

Lists files in the root user's home directory.

12. /run (Runtime Data)

Stores volatile runtime information like process IDs.

Example:

ls /run
Enter fullscreen mode Exit fullscreen mode

Lists runtime data files.

13. /sbin (System Binaries)

Contains essential system administration commands.

Example:

ls /sbin
Enter fullscreen mode Exit fullscreen mode

Lists administrative commands.

14. /srv (Service Data)

Stores data related to services like web servers (/srv/www).

Example:

ls /srv
Enter fullscreen mode Exit fullscreen mode

Lists stored service data.

15. /sys (System Information)

Virtual filesystem providing real-time access to kernel and hardware information.

Example:

ls /sys
Enter fullscreen mode Exit fullscreen mode

Displays system-related files.

16. /tmp (Temporary Files)

Used for storing temporary files.

Example:

ls /tmp
Enter fullscreen mode Exit fullscreen mode

Lists temporary files.

17. /usr (User Binaries and Libraries)

Contains user applications, libraries, documentation, and source code.

Example:

ls /usr/bin
Enter fullscreen mode Exit fullscreen mode

Lists user command binaries.

18. /var (Variable Data)

Stores variable files like logs and caches.

Example:

ls /var/log
Enter fullscreen mode Exit fullscreen mode

Lists system logs.

File Management in Linux

Understanding file management is essential for effective use of the Linux file system.

File Types in Linux

  1. Regular Files (-************************): Text, binary, and executable files.

  2. Directories (d************************): Containers that hold files.

  3. Symbolic Links (l************************): Pointers to other files.

  4. Special Files:

Character devices (c): /dev/tty

Block devices (b): /dev/sda

Named pipes (p), sockets (s)

Important File Operations with Examples

Viewing Files:

cat filename
less filename
Enter fullscreen mode Exit fullscreen mode

Copying Files:

cp source.txt destination.txt
Enter fullscreen mode Exit fullscreen mode

Moving/Renaming Files:

mv oldname.txt newname.txt
Enter fullscreen mode Exit fullscreen mode

Deleting Files:

rm filename
Enter fullscreen mode Exit fullscreen mode

Changing File Permissions:

chmod 755 script.sh
Enter fullscreen mode Exit fullscreen mode

Changing File Ownership:

chown user:group filename
Enter fullscreen mode Exit fullscreen mode

Creating a Symbolic Link:

ln -s /path/to/file linkname
Enter fullscreen mode Exit fullscreen mode

Finding Files:

find / -name "file.txt"
Enter fullscreen mode Exit fullscreen mode

Checking Disk Usage:

df -h
Enter fullscreen mode Exit fullscreen mode

Conclusion

The Linux file system is well-organized and follows a standardized hierarchy that makes file management efficient. By understanding the structure, directories, and file handling commands, users can navigate and manage their Linux systems effectively. Whether you are a beginner or an intermediate user, mastering the Linux file system is a crucial step in your Linux journey.

Top comments (0)