Open In App

Bash Script – File system

Last Updated : 02 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
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.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads