Bash Script – File system
Last Updated :
02 Jan, 2023
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.
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.
- 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.
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.
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 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 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
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
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.
Similar Reads
Bash Script - Read User Input
Interacting with users is a crucial aspect of many Bash scripts. Whether prompting for information, selecting options, or confirming actions, reading user input is essential for building powerful and flexible scripts. This guide provides a comprehensive overview of reading user input in Bash, coveri
8 min read
Shell Scripting - Define #!/bin/bash
A shell provides an interface to connect with the system. When we use an operating system, we indirectly interact with the shell. While using a terminal every time on any Linux distribution system, we interact with the shell. The main function of the shell is to interpret or analyze Unix commands. A
3 min read
Linux File System
Operating systems, the software that powers your computer, rely on a crucial element known as the file system. Think of it as a virtual organizational tool that manages, stores, and retrieves your data efficiently. In the Linux world, a diverse range of file systems has emerged, each crafted to addr
11 min read
Bash Script - Features
These days, there are various shell writing options available out there, and each one of them has its own unique features. Just as it does, Bash Shell contains some of the best features that make it more productive and usable. For each project, there are specific requirements for the features, and t
3 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
Bash Script - File Permissions
In this article, we will discuss file permission in Bash Script To understand the scenario let's take an example. Let's consider there is a system admin A for company XYZ he designs a script that is to be executed by a user at 8:00 PM daily to send a report. He designs the script but forgets to give
5 min read
Batch Script - Strings
A Bash script is a plain text file. This file contains different commands for step-by-step execution. These commands can be written directly into the command line but from a re-usability perceptive it is useful to store all of the inter-related commands for a specific task in a single file. We can u
4 min read
How To Run Bash Script In Linux?
Bash scripts, also known as shell scripts, are powerful tools in the world of command-line automation. They allow you to perform a series of tasks or execute commands by writing scripts that can be run in a terminal or command-line interface. However, the question often arises: how do you run a Bash
6 min read
Shell Script Examples
For all the Linux distributions, the shell script is like a magic wand that automates the process, saves users time, and increases productivity. This shall scripting tutorial will introduce you to the 25 plus shall scripting examples. But before we move on to the topic of shell scripting examples, l
15+ 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