Understanding Linux File Systems

So what is a file system? Well, in simple terms, it’s just a way for your computer to organize and store all of its files. On Linux, there are several different types of file systems you can use, but we’re going to focus on the most popular one: ext4 (pronounced “ex-tee-four”).

Now let me explain how it works in more detail. When you create a new folder or save a document, that data is stored on your hard drive using blocks of information called sectors. These sectors are grouped together into larger units called clusters, which can contain anywhere from 1 to thousands of sectors depending on the size of the file system and the type of disk being used.

When you want to access a particular file or folder, Linux uses an indexing system called an inode (pronounced “in-oh-dee”) to keep track of where everything is stored. Each inode contains information about its corresponding file or directory, such as its size, permissions, and location on the disk.

So let’s say you have a folder named “documents” that contains several subfolders with different types of files inside them (like PDFs, Word documents, and images). When you open up your terminal and type “ls -l”, it will display a list of all the files in that directory along with their corresponding inode numbers.

Here’s an example:

bash
# This script lists all the files in the "documents" directory and their corresponding inode numbers.
# The "ls -l" command displays a long listing of the files, including their permissions, owner, group, size, date modified, and name.

# Change directory to "documents"
cd documents/

# List all files in the directory
ls -l

# Output:
# total 16K
# drwxr-x---  2 user group   4.0K Apr 15 17:38 documents/
# -rw-r--r--  1 user group    98B Apr 15 17:38 document_1.pdf
# -rw-r--r--  1 user group    62K Apr 15 17:40 document_2.docx
# drwxr-x---  2 user group   4.0K Apr 15 17:41 folder_1/
# -rw-r--r--  1 user group    38K Apr 15 17:42 image_1.jpg

# The first line shows the total number of files in the directory (16K).
# The following lines show the permissions, owner, group, size, date modified, and name of each file.
# The first character in each line indicates the type of file (d for directory, - for regular file).
# The next 9 characters represent the permissions for the owner, group, and others (r for read, w for write, x for execute).
# The next number represents the number of hard links to the file.
# The next two fields represent the owner and group of the file.
# The next field represents the size of the file in bytes.
# The next field represents the date and time the file was last modified.
# The last field represents the name of the file.

# Note: The inode number is not displayed in the output, but it can be found by using the "ls -i" command.

As you can see, each file and directory has its own unique inode number (listed in the second column), which is used to identify it on the disk. The “d” at the beginning of the first line indicates that this is a directory, while the “-” symbol means that everything else is a regular file.

That’s how ext4 works under the hood. It may seem like a lot to take in at first, but once you get used to it, it’ll become second nature. And who knows? Maybe one day you’ll even be able to write your own scripts and commands using Bash (but let’s not get ahead of ourselves).

So basically, when we create a new folder or save a document on Linux, the data is stored in sectors which are grouped together into clusters. Each cluster can contain anywhere from 1 to thousands of sectors depending on the size of the file system and type of disk being used. To keep track of where everything is stored, Linux uses an indexing system called an inode that contains information about its corresponding file or directory such as its size, permissions, and location on the disk. When we open up our terminal and type “ls -l”, it displays a list of all the files in that directory along with their corresponding inode numbers. Each file and directory has its own unique inode number which is used to identify it on the disk.

SICORPS