Linux File Structure

Linux File Structure

The Linux file structure can seem complex at first, but it's quite logical once you get the hang of it. Think of it like a big filing cabinet, where each drawer and folder has a specific purpose. Here’s a simple breakdown:

Root Directory (/)

  • The root directory is like the top drawer of the filing cabinet. Everything in the Linux file system starts here.

  • Example: /home, /bin, /etc
    to go to the room directly:you use the cd (change directory) command followed by a single forward slash (/).

Home Directory (/home)

  • Description: This is where all your files and folders live. Each user on the system has their subdirectory here.

  • Example: /home/john for a user named John. Inside, John might have folders like Documents, Downloads, and Pictures.
    To go to home type : cd /home

Bin Directory (/bin)

  • Description: Think of this as the drawer for all the important tools. It contains essential command binaries (executables) needed for the system to work properly.

  • Example: /bin/ls (used to list files), /bin/cp (used to copy files)

Sbin Directory (/sbin)

  • Description: This drawer is for system binaries, which are crucial tools for system administration. Regular users don’t usually need these tools.

  • Example: /sbin/reboot (used to restart the system), /sbin/fsck (used to check and repair filesystems)

Etc Directory (/etc)

  • Description: This is the drawer for configuration files. It’s where the system settings and configurations are stored.

  • Example: /etc/passwd (file that stores user account information), /etc/hosts (file that maps hostnames to IP addresses)

Var Directory (/var)

  • Description: This drawer is for variable files—files that are expected to change as the system runs. Think of it as the place for logs, spool files, and other data that’s constantly being updated.

  • Example: /var/log (stores system log files), /var/mail (stores user email)

Tmp Directory (/tmp)

  • Description: This drawer is for temporary files. It’s like a scratchpad where the system and applications can store temporary data.

  • Example: /tmp (used by various applications to store temporary data)

Usr Directory (/usr)

  • Description: This is a big drawer that contains user-installed software and applications, libraries, documentation, and more.

  • Example: /usr/bin (contains user-level binaries), /usr/lib (contains libraries needed by binaries in /usr/bin)

Lib Directory (/lib)

  • Description: This drawer holds essential shared libraries needed by binaries in /bin and /sbin. Think of libraries as helpers that other programs use to perform tasks.

  • Example: /lib/libc.so.6 (a fundamental library for the C programming language)

Dev Directory (/dev)

  • Description: This is the drawer for device files. These files represent hardware devices like disks, printers, and so on.

  • Example: /dev/sda1 (the first partition on the first hard disk), /dev/tty1 (a terminal device)

Mnt Directory (/mnt)

  • Description: This is a temporary mount point for filesystems. When you insert a USB drive or mount an external hard drive, you often mount it here.

  • Example: /mnt/usb (a mounted USB drive)

Proc Directory (/proc)

  • Description: This is a virtual filesystem that contains information about system processes and other system information. It’s like a window into the system’s brain.

  • Example: /proc/cpuinfo (information about the CPU), /proc/meminfo (information about memory)

Opt Directory (/opt)

  • Description: This drawer is for optional software. When you install additional software, especially third-party software, it might go here.

  • Example: /opt/lampp (XAMPP server software)

Media Directory (/media)

  • Description: Similar to /mnt, but often used for automatically mounted filesystems like CDs, DVDs, and USB drives.

  • Example: /media/cdrom (a mounted CD-ROM)

Example Structure:

/
├── home
│   ├── john
│   │   ├── Documents
│   │   ├── Downloads
│   │   └── Pictures
├── bin
│   ├── ls
│   └── cp
├── sbin
│   ├── reboot
│   └── fsck
├── etc
│   ├── passwd
│   └── hosts
├── var
│   ├── log
│   └── mail
├── tmp
├── usr
│   ├── bin
│   └── lib
├── lib
│   └── libc.so.6
├── dev
│   ├── sda1
│   └── tty1
├── mnt
│   └── usb
├── proc
│   ├── cpuinfo
│   └── meminfo
├── opt
│   └── lampp
└── media
    └── cdrom

Summary

  • Root (/): The top-level directory.

  • Home (/home): Personal files and folders for each user.

  • Bin (/bin): Essential user commands.

  • Sbin (/sbin): System administration commands.

  • Etc (/etc): Configuration files.

  • Var (/var): Variable data like logs.

  • Tmp (/tmp): Temporary files.

  • Usr (/usr): User-installed software and libraries.

  • Lib (/lib): Essential shared libraries.

  • Dev (/dev): Device files.

  • Mnt (/mnt): Temporary mount points.

  • Proc (/proc): Virtual filesystem for system information.

  • Opt (/opt): Optional software.

  • Media (/media): Mounted removable media.

This structure helps keep the system organized and ensures that files are easily accessible based on their purpose.