Linux Files and Directory System
- Linux OS comes with a well-defined file structure where user files are arranged in a definite directory structure. According to the type of files, the directories are categorized as Binary directories, configuration directories, Data directories, memory directories, USR (Unix System Resources), var(variable directory), and non-standard directories.
- The Linux file system is a crucial part of the operating system, organizing data and managing how files are stored, retrieved, and manipulated.
- The Linux file system follows a hierarchical directory structure, beginning at the root directory (
/
), and supports multiple file system types that are tailored to different use cases, such as performance, reliability, or flexibility. - Linux supports various file systems, each optimized for specific needs. These are –
(A) Common Directories in the Linux
-
- A Linux directory system consists of –
-
- The Linux file system is structured in a tree hierarchy, where the top-most directory is the root directory (
/
). All files and directories start from this root, and Linux adheres to a standardized file system layout called the Filesystem Hierarchy Standard (FHS). FHS is the directory structure and directory contents in Linux are defined by a body called ‘The File system Hierarchy Standard (FHS). - The directory structure and directory contents are maintained by the Linux Foundation.
- According to FHS, all files and directories appear/are included under the root directory( /), even if they are stored on different physical drives or virtual devices.
- Linux contains several directories which contain many Linux files and have different unique functions.
- Some important standard directories are – root directory(/), bin directory(/bin), dev directory(/dev), boot directory(/boot), etc directory(/etc), lib directory(/lib), home directory(/home), media directory(/media), opt directory(/opt), tmp directory(/tmp), sys directory(/sys), usr directory(/usr), var directory(/var) etc.
- The Linux file system is structured in a tree hierarchy, where the top-most directory is the root directory (
-
-
-
/
(Root Directory):- The base of the Linux file system hierarchy.
- All other files and directories are contained within it.
-
/bin
:- This file contains essential binary executable files (commands) required for booting the system and running in single-user mode.
- Example commands include
ls
,cp
,mv
, andcat
.
-
/sbin
:- This Linux file contains system binaries used by the system administrator for essential system management tasks, like
fsck
,reboot
, andifconfig
.
- This Linux file contains system binaries used by the system administrator for essential system management tasks, like
-
/etc
:- This Linux file stores system-wide configuration files.
- For example,
/etc/passwd
contains user account information, and/etc/fstab
holds file system mounting information.
-
/dev
:- This Linux file contains device files that represent hardware components (e.g., hard drives, USB devices, etc.).
- Files like
/dev/sda
represent the first hard drive.
-
/proc
:- This is a virtual file system that provides information about system processes and kernel parameters.
- It is dynamically generated at runtime.
- Files like
/proc/cpuinfo
contain CPU information.
-
/sys
:- This is another virtual file system, similar to
/proc
, providing a mechanism to communicate with the kernel, including system devices, drivers, and modules.
- This is another virtual file system, similar to
-
/usr
:- This Linux file contains user utilities and applications. It often contains subdirectories such as:
/usr/bin
: Non-essential binaries./usr/sbin
: Non-essential system binaries for system management./usr/lib
: Libraries for applications in/usr/bin
and/usr/sbin
.
- This Linux file contains user utilities and applications. It often contains subdirectories such as:
-
/var
:- This Linux file stores variable files that are expected to grow in size, such as log files (
/var/log
), spool files (for printers, mail, etc.), and temporary files.
- This Linux file stores variable files that are expected to grow in size, such as log files (
-
/tmp
:- This is a temporary directory used for storing temporary files by both users and system processes.
- This directory is often cleared during boot.
-
/home
:- This file contains home directories for individual users.
- For example, the home directory for a user
alice
would be/home/alice
, where their personal files and configurations are stored.
-
/lib
and/lib64
:- This Linux file contains essential shared libraries and kernel modules needed by programs in
/bin
and/sbin
.
- This Linux file contains essential shared libraries and kernel modules needed by programs in
-
/boot
:- This Linux file contains files needed for booting the system, such as the Linux kernel (
vmlinuz
), bootloader files (GRUB or LILO), and the initial RAM disk image (initrd
orinitramfs
).
- This Linux file contains files needed for booting the system, such as the Linux kernel (
-
/opt
:- This file is used for optional software and third-party applications that are not part of the default Linux distribution.
-
/media
and/mnt
:- These directories are used for mounting removable devices or other file systems.
/media
is typically used for automatically mounting USB devices or CDs, while/mnt
is used for manual mounts.
- These directories are used for mounting removable devices or other file systems.
-
/root
:-
This is the home directory of the root user (the system administrator).
-
It is separate from regular user home directories, which are under
/home
.
-
-
-
(B) Types of Files in the Linux
-
-
Regular Files:
- The most common file type, representing readable, writable, or executable data (e.g., text files, executable binaries).
-
Directories:
- These are special files that contain other files and directories.
- They act as containers organizing the file system structure.
-
Symbolic Links/Soft Links:
- This is a pointer file that points to another file or directory.
- They function like shortcuts.
- It changes to the original file affect the symbolic link, but deleting the symbolic link does not delete the target file.
-
Hard Links:
- It is another pointer to a file that shares the same inode.
- Unlike symbolic links, hard links remain valid even if the original file is deleted, as long as one hard link exists.
-
Device Files:
- This file represents hardware devices, allowing user-space programs to communicate with the hardware.
- They are located in
/dev
directory and are divided into:- Character Devices: It provides unbuffered, direct communication with hardware devices (e.g.,
/dev/tty
for terminals). - Block Devices: This is used for buffered I/O operations, usually with storage devices (e.g.,
/dev/sda
for disks).
- Character Devices: It provides unbuffered, direct communication with hardware devices (e.g.,
-
Pipes:
- It is a special file that allows inter-process communication.
- Data written by one process can be read by another using piping techniques.
-
Sockets:
-
It is also a special file used for network communication between processes.
-
-
(C) Category of Linux File System
The most common file systems are as follows:-
-
-
Ext4 (Fourth Extended File System):
- This file is the Default file system for most Linux distributions.
- This file improves reliability and helps recover from system crashes.
- It supports large file sizes (up to 16 TB) and volumes (up to 1 EB).
- This file is efficient with large directories and handles fragmentation well.
-
XFS:
- It is a scalable file system designed for large file systems and high-performance computing.
- This file system is optimized for parallel I/O operations.
- This file system is used in enterprise-level Linux systems like Red Hat.
-
Btrfs (B-Tree File System):
- This file system is designed for advanced features like snapshotting, subvolumes, and integrated RAID.
- This file system aims to replace ext4 in some systems due to its advanced capabilities.
- This file system supports dynamic resizing, better data integrity, and file system snapshots.
-
FAT32/exFAT:
- This is a Cross-platform file system often used for removable media like USB drives.
- FAT32 has file size limitations (max 4 GB per file), while exFAT addresses this, supporting larger files.
-
NTFS:
- This is a Microsoft file system used in Windows.
- Linux can read NTFS natively, and with tools like
ntfs-3g
, it can also write to NTFS partitions.
-
Swap File System:
- This file system is used as virtual memory or swap space, a reserved part of the hard drive to act as RAM when physical memory is full.
- This is not a typical file system but a specific partition used by the Linux kernel for swapping processes in and out of memory.
-
ZFS (Zettabyte File System):
- This file system was originally developed by Sun Microsystems, ZFS is known for its high data integrity, scalability, snapshots, and native RAID-like functionality.
- It is often used in enterprise environments and for data storage servers.
-
ISO 9660:
-
This file system is a file system for optical discs (CD/DVD).
-
It is used to access data on ISO files and physical media.
-
-
(D) Structure of Linux File System
BOOT BLOCK
-
- It is one of the major components of a Linux file system.
- This component is located in the first few sectors of a Linux file system.
- The boot block contains the initial bootstrap program which is used to load the operating system during the loading process.
SUPER BLOCK
-
- It is another major component of a Linux file system.
- A superblock describes the state of the file system i.e. it includes the total size of the partition, the block size, pointers to a list of free blocks, the inode number of the root directory, magic number, etc.
INODE TABLE
-
- ‘inodes‘ stands for index nodes.
- inode table is mainly used to handle different types of Linux files.
- inode is a tabular structure, as a linear array form, which contains various important information regarding the Linux file process. These are –
- file ownership information.
- file type/Nature of file (such as regular, directory, special device, pipes, etc.).
- file access permissions.
- time of last access, last modification, etc.
- number of links (aliases) to the file.
- pointers associated with the data blocks for the file.
- size of the file in bytes (for regular files).
- major and minor device numbers for special devices.
- An inode is identified by its inode number, which contains the information needed to find the inode itself on the disk.
DATA BLOCKS
-
- Data blocks contain the actual contents/data of files.
- The Linux file system allocates data blocks one at a time from a pool of free blocks.
Architecture of Linux
- The architecture of Linux refers to the structure and components that make up the Linux operating system.
- Linux is based on the Unix architecture and is a monolithic kernel system, a monolithic kernel is a type of operating system architecture where the entire kernel/OS, including all core services and device drivers, runs in a single or same address/memory space (kernel space), providing high performance and efficiency. The Linux kernel, as well as other traditional Unix-like kernels, is an example of a monolithic kernel.
- A typical Linux consists of primarily the following components: – Hardware, Kernel, Shell, and Utilities (and a layer of Users)
Hardware Layer :
-
- Peripheral devices such as RAM, HDD, CPU, and other related components constitute a Hardware layer for the Linux operating system.
- The innermost layer of the Linux.
- They are responsible for processing the instructions given.
Kernel Layer :
-
- The Core/main part of the Linux OS is called Kernel.
- The Kernel interacts directly with the hardware to complete the given instructions.
- It manages hardware resources, provides abstractions to higher-level software, and ensures that different processes operate smoothly.
- There may be two types of kernels – Monolithic Kernel and Micro Kernel.
- The kernel itself has several subsystems and is responsible for doing almost all activities of the Linux operating system. These are -:
- Process Management:
- This part of Kernel manages the execution of processes, multitasking, process scheduling, and inter-process communication (IPC).
- Memory Management:
- This part of Kernel handles memory allocation and deallocation, virtual memory, and swapping between RAM and disk storage.
- File System Management:
- This part of Kernel provides access to different types of file systems (EXT4, NTFS, FAT32, etc.) and manages file operations like reading and writing.
- Device Drivers:
- This part of Kernel interfaces with hardware devices, allowing the kernel to interact with peripherals such as storage devices, network cards, and printers.
- Networking:
- This part of Kernel provides support for various network protocols and enables communication between systems over a network.
- Process Management:
Shell Layer:
-
- The shell layer in Linux is a crucial part of the operating system’s user space, providing an interface for users to interact with the system.
- The shell sits between the user and the kernel. When a user issues a command in the shell, the shell interprets the command and makes a system call to the kernel to execute the requested task.
- The shell is an interface between the user and the kernel. It accepts commands from the user and acts. In other words, the shell acts as a command-line interpreter/interface that takes input from the user interprets it, and then communicates with the operating system kernel to execute commands.
- The shell is a program that translates human-readable commands into kernel-understandable instructions via system calls.
- The shell allows users to execute commands by typing them into the terminal.
- Shells provide mechanisms for input/output redirection. Users can redirect the input or output of commands using symbols like
>
,<
, and|
. For example,ls > file.txt
will redirect the outputls
to a file. - Shells manage environment variables, which are values stored in memory and used by the shell and applications.
- Modern shells support job control, which allows users to start, stop, and resume processes. Commands like
fg
(foreground),bg
(background), andjobs
are used to manage tasks running in the background or foreground. - The shell layer hides the complexity of functions of the kernel from the user.
- The shell prompt is the interface where users type their commands. It typically includes details such as the username, hostname, current directory, and a symbol. (The shell prompt
$
is represented for regular users and#
for root users). - A shell script is a file containing a series of commands that are executed in sequence by the shell. These scripts can automate repetitive tasks and are used extensively in Linux for system management. For example – (save as script.sh)
-
#!/bin/bashecho “Hello, World!”echo “Hello, India!”To execute the shell script file./script.sh
- Types of Shells
There are several different types of shells available in Linux, each with unique features and syntax. Some of the most commonly used shells are as follows:-
- Bash Shell(Bourne Again Shell):
- The most common shell in Linux distributions is mostly used in Shell programming.
- Bash is an enhanced version of the original Bourne shell (sh).
- This shell supports command-line editing, scripting, and job control.
- Zsh (Z Shell):
- A powerful, feature-rich shell that includes advanced auto-completion, theme support, and improved scripting.
- Fish (Friendly Interactive Shell):
- This shell is designed to be user-friendly, Fish provides intuitive syntax highlighting, suggestions, and other features focused on ease of use.
- Dash:
- A lightweight, POSIX-compliant shell.
- Dash is commonly used for system scripts because it is faster and simpler than Bash.
- Tcsh and Csh (C Shell):
- Csh (and its variant Tcsh) is a shell with C-like syntax, commonly used in BSD-based systems.
- Bash Shell(Bourne Again Shell):
Utility Layer:
-
- The utility layer in Linux refers to the collection of command-line tools, utilities, and applications that sit on top of the kernel and interact with the shell layer to provide users with powerful and flexible functionality.
- This layer includes basic system tools and more complex applications that allow users to perform various tasks, from file manipulation to networking and system administration.
- The operating system performs functions granted to the user by Utilities.
- The utility layer contains several utilities in the form of commands that can be categorized into the following groups as follows –
- Core system utilities handle basic file management, process control, and text processing.
- User and system management utilities deal with users, groups, permissions, and system monitoring.
- Networking utilities cover everything from basic connectivity tests to advanced network monitoring.
- File compression utilities manage compression and decompression.
- Package management tools install and update software.
- Development tools like compilers and debuggers aid in software creation.
- Text editors enable system configuration and programming.
- Shell scripting utilities support automation.
- Backup tools manage data and system recovery.
- Security utilities protect the system and encrypt sensitive data.
These utilities form a critical layer of the Linux operating system, allowing users and administrators to manage the system efficiently and perform complex tasks directly from the command line or through scripts using different types of commands as needed.
User Layer:
-
- This is the outermost layer of Linux OS where users can interact with several applications/commands of the Utility layer as per their need.
0 Comments