Skip to content
Home » File Structure and hierarchy

File Structure and hierarchy

Understanding Files and File System: Files and Directories in Linux


1. Introduction

In Linux, everything is treated as a file—documents, directories, devices, and even running processes. The Linux file system provides a structured way to store, organize, and manage data using files and directories.

Understanding files and directories is fundamental for Linux usage, system administration, and exams.


2. What is a File in Linux?

A file is a collection of data stored on disk with a name and attributes.

Types of Files in Linux

Linux supports multiple file types:

File TypeDescriptionSymbol
Regular fileText, binary, scripts-
DirectoryContains filesd
Character deviceKeyboard, mousec
Block deviceHard diskb
Symbolic linkShortcut to filel
SocketNetwork communications
FIFO (pipe)Inter-process communicationp

📌 Command to view file type:

ls -l

3. File Attributes

Each file in Linux has attributes:

  • File name
  • File type
  • Permissions (read, write, execute)
  • Owner and group
  • Size
  • Time stamps (created, modified, accessed)

Example:

-rw-r--r-- 1 user group 1024 file.txt

4. What is a Directory?

A directory is a special type of file that stores names and locations of other files.

Directories help in:

  • Organizing files
  • Creating a hierarchical structure
  • Efficient file management

5. Linux Directory Structure (File System Hierarchy)

Linux follows a single-rooted, tree-like structure starting from / (root directory).

Important Directories

DirectoryPurpose
/Root directory
/binEssential commands
/sbinSystem admin commands
/etcConfiguration files
/homeUser home directories
/rootRoot user’s home
/varVariable data (logs)
/tmpTemporary files
/devDevice files
/procProcess information
/usrUser applications

6. Understanding Paths

Absolute Path

  • Starts from root /
  • Example:
/home/user/file.txt

Relative Path

  • Starts from current directory
  • Example:
../file.txt

7. File and Directory Permissions

Linux uses permission-based security.

Permission Types

  • r – Read
  • w – Write
  • x – Execute

Permission Levels

  • Owner
  • Group
  • Others

Example:

-rwxr-xr--

8. Common File & Directory Commands

File Commands

touch file.txt
cat file.txt
rm file.txt
cp file1 file2
mv old new

Directory Commands

mkdir folder
rmdir folder
cd folder
ls

9. Links in Linux

Hard Link

  • Points to same inode
  • Cannot link directories
  • Survives file deletion

Symbolic Link

  • Points to file path
  • Can link directories
  • Broken if original deleted

Command:

ln file1 file2      # hard link
ln -s file1 link1   # soft link

10. File System in Linux

The file system defines how files are:

  • Stored
  • Organized
  • Retrieved

Common Linux File Systems

  • ext4 (most common)
  • XFS
  • Btrfs
  • FAT, NTFS (supported)

11. Mounting File Systems

Linux uses mount points to access file systems.

Example:

mount /dev/sda1 /mnt

12. Special Files Concept

  • /dev → hardware as files
  • /proc → running processes as files
  • /sys → kernel info

📌 Reinforces: Everything is a file


13. Advantages of Linux File System

  • Strong security
  • Organized hierarchy
  • Supports large file sizes
  • Highly stable and efficient

14. Conclusion

Linux treats files and directories as core building blocks of the operating system. Its hierarchical file system structure, strong permissions, and flexible file handling make Linux secure, powerful, and efficient, especially for servers and multi-user environments.