Open In App

Bash Script – File system

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 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.

Types of Linux File Systems

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.

 

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

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

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

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.


Article Tags :