DEV Community

Anand Ghangoria
Anand Ghangoria

Posted on

Linux : Mastering File System

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:
Image description

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:

Lists all top-level directories.

2. /bin (Binary Executables)

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

Example:

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:

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:

Lists available storage devices.

5. /etc (Configuration Files)

Stores system-wide configuration files and scripts.

Example:

Displays system user account details.

6. /home (User Home Directories)

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

Example:

Lists all user directories.

7. /lib & /lib64 (Shared Libraries)

Stores essential shared libraries required by system programs.

Example:

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:

This mounts an external drive and lists its contents.

9. /opt (Optional Software)

Contains software installed by third-party vendors.

Example:

Lists installed optional software.

10. /proc (Process Information)

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

Example:

Displays CPU details.

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

Home directory for the root user.

Example:

Lists files in the root user's home directory.

12. /run (Runtime Data)

Stores volatile runtime information like process IDs.

Example:

Lists runtime data files.

13. /sbin (System Binaries)

Contains essential system administration commands.

Example:

lists of administrative commands.

14. /srv (Service Data)

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

Example:

Lists stored service data.

15. /sys (System Information)

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

Example:

Lists a Displays system-related files.

16. /tmp (Temporary Files)

Used for storing temporary files.

Example:

Lists temporary files.

17. /usr (User Binaries and Libraries)

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

Example:

Lists user command binaries.

18. /var (Variable Data)

Stores variable files like logs and caches.

Example:

Lists system logs.

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.

Special Files:

Character devices (c): /dev/tty

Block devices (b): /dev/sda

Named pipes (p), sockets (s)

Important Linux commands for 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

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.