Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App
Next Article:
Bash Script - File system
Next article icon

Bash Script - File system

Last Updated : 02 Jan, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

On a partition or disc, a file system is a logical grouping of files. A partition serves as a storage space for data and, if needed, can take up the entire hard disc. One file system may house the /file system, while another may house the /home file system. Your hard drive may have a variety of partitions, each of which typically only contains one file system. The logical upkeep and management of various file systems are made possible by one file system per partition. Physical objects like DVD-ROMs, USB drives, and floppy drives are all regarded as files in the Unix operating system.

Linux File System

Following are the sections contained by the Linux file system:

  • The root directory (/).
  • A specific data storage format (ETX3, ETX4, BTRFS, XFS, and many more).
  • A logical volume or partition with a certain file system.

The root directory and its child directories give the Linux file system a hierarchical file structure. Access to all other directories is available from the root directory. A partition normally contains a single file system, but it is possible for it to have several.

Linux File System Structure

A two-part file system software implementation architecture is included in the Linux file system.

Linux File System Structure
 

In order to access the function calls and interact with file system elements like files and directories, the file system needs an API (application programming interface). File creation, deletion, and copying are made easier via API. It makes it easier for an algorithm to specify how files should be organized on a file system.

A Linux virtual file system is the collective name for the first two components of the supplied file system. The file system can be accessed by the kernel and programmers using a single set of commands. To provide an interface to the file system, this virtual file system needs a specific system driver.

Types of Linux File Systems

  •  EXT file system: Extended File System is the name of the file system. It was created primarily for MINIX OS. EXT is an outdated file system that is no longer utilized because of several restrictions. EXT2, EXT3, and EXT4 are its updated versions.
  • JFS file system: Journaled File System, or JFS for short, is a program created by IBM for AIX Unix. When CPU power is constrained, this file system comes in handy. In place of the EXT file system, it is an alternative. It can also be utilized in situations when stability is required with minimal resources in place of EXT.
  • ReiserFS file system: Journaled File System, or JFS for short, is a program created by IBM for AIX Unix. When CPU power is constrained, this file system comes in handy. In place of the EXT file system, it is an alternative. It can also be utilized in situations when stability is required with minimal resources in place of EXT.
  • XFS file system: The XFS file system, which was created for parallel I/O processing, was regarded as a high-speed JFS.
  • BTRFS file system: The B tree file system is referred to as BTRFS. It is utilized for fault tolerance, extensive storage configuration, fun administration, and more. It does not fit the production system well.
  • Swap file system: During system hibernation, the Linux operating system uses the swap file system for memory paging. A system must have swap space that is equivalent to the size of its RAM if it never enters the hibernation state.

Directory Structure

With root (/) as the root of the file system and all other directories branching out from there, Unix uses a hierarchical file system topology that resembles an upside-down tree.

Directory Structure of Linux
 


A collection of files and directories with the following characteristics is known as a Unix filesystem:

  • There are more files and directories in its root directory (/).
  • Each file or directory has a unique identifier that is commonly referred to as an inode, as well as its name and the directory in which it is located.
  • The root directory and the lost+found directory each have an inode number of 2, according to the convention. There is no use for inode numbers 0 or 1. Use the -i option of the ls command to view file inode numbers.
  • It can stand alone. The relationship between one filesystem and another is independent.

The directories are used for specific things and typically contain the same kinds of data so that files may be found quickly. The directories that are present on the most popular Unix versions are listed below:

Sr. No.

Directory & Content

1

/

Only the directories required at the top level of the file structure should be present in this root directory.

2

 /bin

The executable files are available here. All users have access to these files.

3

/dev

Device drivers are these.

4

/etc

Commands for the supervisor directory, disc configuration files, valid user lists, groups, ethernet, hosts, and locations to convey urgent messages.

5

/lib

Contains shared library files, as well as occasionally additional kernel-related files.

6

/boot

Contains files needed for the system to boot.

7

/home

Contains users' and other accounts' home directories.

8

/mnt

Used to mount alternative temporary file systems for the CD-ROM drive and floppy diskette drive, respectively, such as cdrom and floppy.

9

/proc

Contains all processes identified as files by process number or other dynamic system metadata.

10

/tmp

Transient files used between system booting are stored here.

11

/usr

Widely applicable and used for a variety of reasons. comprises administrative commands, shared files, library files, and other types of files.

12

/var

Contains files with variable lengths, such as log and print files, as well as any other kind of file that might have a variable quantity of data in it.

13

/sbin

Contains executable (binary) files that are typically used for system administration. For instance, the utility fdisk and ifconfig.

14

/kernel

Includes kernel files.

Navigating the file system

  • cd <DESTINATION>: Change directory.
  • ls: List files.
  • touch <FILE_NAME> : Create files.
  • cat <FILE_NAME> : Show file contents.
  • cp <SOURCE/FILE_NAME> <DESTINATION> : Copying files.
  • mv <SOURCE/FILE_NAME> <DESTINATION> : Moving a file.
  • mv <FILE_NAME> <NEW FILE NAME> : Renaming a file. mv can be used to rename a file.
  • rm <FILE_NAME> : Delete a file.

Example 1: The df Command

The df (disc free) command is the first tool you may use to control the space on your partitions. As illustrated below, the df -k (disc free) command shows the amount of disc space used in kilobytes.

df -k
df command
df command execution

Some of the directories, such /devices, display 0% for capacity and 0 in the kbytes, used, and available columns. Though they are located on the disc under /, these unique (or virtual) file systems don't take up any space on the disc on their own.

To display the results in a format that illustrates the size in notation that is simpler to grasp, use the -h (human-readable) option.

Example 2: The du Command

du   du -h

You can specify directories using the du (disc usage) command to view the amount of disc space used by a certain directory.

If you want to know how much space a specific directory is using, this command can be useful. The next command shows how many blocks each directory has utilized. Depending on your system, a single block may require 512 bytes or 1 kilobyte.

du command
du command execution

Example 3: Mounting the File System

In order for the system to use a file system, it must first be mounted. Use the command below to check what is currently mounted (available for use) on your system.

cd  mount
mounting file system
 

According to the Unix convention, temporary mounts (including CDROM drives, remote network drives, and floppy drives) are stored in the /mnt directory. The mount command can be used to mount a file system with the following syntax:

mount -t file_system_type device_to_mount directory_to_mount_to

Unmounting the File System

Use the umount command and provide the mount point or device to unmount (delete) the file system from your system. You can access your file systems using the mount command, however, on the majority of contemporary Unix systems, the automount function hides this operation from the user and doesn't require human interaction.

For instance, execute the following command to unmount a CDROM.

$ umount /dev/cdrom

You can access your file systems using the mount command, however, on the majority of contemporary Unix systems, the automount function hides this operation from the user and doesn't require human interaction.


Next Article
Bash Script - File system

V

vyavaharepranav11
Improve
Article Tags :
  • Technical Scripter
  • Linux-Unix
  • Write From Home
  • Technical Scripter 2022
  • Bash-Script

Similar Reads

    Linux File System
    A file system is a structured method of storing and managing data—including files, directories, and metadata—on your machine. Think of it like a library. If thousands of books were scattered around, finding one would be hard. But in an organized structure, like labeled shelves, locating a book becom
    12 min read
    OS File System Architecture
    An operating system (OS) is software that manages computer hardware and software resources and provides related services to computers. It acts as an intermediary between applications and computer hardware. What is a Document System?A file system is a method that helps in organizing and managing data
    5 min read
    proc file system in Linux
    Proc file system (procfs) is a virtual file system created on the fly when the system boots and is dissolved at the time of system shutdown. It contains useful information about the processes that are currently running, it is regarded as a control and information center for the kernel. The proc file
    4 min read
    File System Mounting in OS
    In this article, we are going to discuss the most important concept in Operating Systems which allows the users to organize and access files from different storage devices. If we compare it to a real-life scenario, it is closely related to “Connecting puzzles to get a complete picture of data”. What
    3 min read
    File System Library in C++17
    In this article, we will learn about the File System library in C++17 and with examples. <filesystem> header was added in C++17 and introduces a set of classes, functions, and types that simplify file system operations. In simple words, we can say that the filesystem library provides tools tha
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences