Linux 101 - The Linux File System

Introduction

The first skill users should develop when working in a Linux terminal is to be able to navigate within the Linux file system. As explained in the previous section, the user interacts with the computer via text command, thus every navigation action will be coupled to a text command.

However, simply learning the commands will not be sufficient to confidently and efficiently navigate the the file system on a Linux system. For this, the user also needs to understand how the file system is structured.

Thus in this section of Linux 101 the user will first be exposed to how the file system in a Linux OS is structured and will then be exposed to the various commands necessary for navigation.

As we delve deeper into how things work in Linux, the relevant concepts will be explained by comparing and contrasting them with equivalent concepts in Windows. Windows is chosen because it is assumed this is the OS that users have had the most exposure to.

File system structure in Linux

A file system is the collection of methods that an OS use(s) to store and manage data on a storage medium (such as a hard drive). Windows uses the NTFS and the FAT family of file systems. Linux provides a more expansive list of supported file systems, but generally ext4 is used. An important note here is that if you format a hard disk with the ext4 file system, you won't be able to access the disk in Windows, however, Linux provided support for the Windows file systems, so you would be able to access an NTFS formatted hard drive in Linux.

While Linux provides support for many file systems, most of the differences between them happens behind the scenes and the user is rarely exposed to the details. Thus, interaction and navigation within the file system in Linux will be the same regardless of the file system used.

Organization of storage devices

It is important to first define the primary storage device in a system. This is a computer or server's primary storage device upon which the OS is installed. With that definition in mind, let's first explore how Windows structures its file system.

Windows

In Windows, the storage devices are attached separately to the file system and given drive letters. The screen shot below shows a Windows 10 system with multiple internal and external hard drives attached:

fs_windows_1

To access a drive we can simply double-click on it and be navigated to the root of the hard drive. Lets do this for DEFILER_MOVIES:

fs_windows_2

This works great in a GUI. However, in non-GUI environments this becomes cumbersome, as one would need to remember drive letters and these can change after reboots, thus making file and directory paths non-fixed.

Linux

Linux organizes storage devices differently. First, storage devices aren't automatically attached (or mounted) within OS by default (This behaviour differs between distributions but can be changed). Instead, you have a single root directory on the primary storage device containing directories and a device is added into the file system by mounting it into a directory under this root directory. This root directory of the file system is represented by the character "/".

An example of a Linux file system is illustrated in the screen shot below (the same computer as the one used for the Windows screen shot above):

fs_linux_1

The directory into which the drives are mounted via the GUI are usually a distribution dependent, default directory. However, mounting a storage device manually via the terminal command mount requires the user to specify a directory (this is called a mount point). Thus a device can be mounted anywhere that the user have access to (more on this later).

On the Linux Mint 20.2 system in the examples, all additional storage devices are mounted in the /media/current_user/ directory:

linux_fs_mount_1

If we go into the DEFILER_MOVIES directory, we can see the contents of the drive in this directory, which is the same as the contents of Drive I in Windows:

linux_fs_mount_2

Notice that the listed amount of free space at bottom of the window changed from 29.2 GB to 1.5 TB. This is because we moved from the primary 240GB SSD to the external USB hard drive that is mounted in the DEFILER_MOVIES directory.

The advantage of mounting storage devices is this way is:

  • The user and programs are presented with a single file system and does not need to know or worry about the details of any of the numerous storage types that may be attached to the system.
  • Permanent mount points (set in a special file that is read at boot-time) make paths permanent and reliable.
  • Navigation via the command Terminal is optimized.

Files and directories

Paths

The above differences in how storage devices are represented in the file system have an effect on how file and directory paths are represented.

Let us consider the Fantasy directory on the external hard drive in our previous example screen shots:

For Windows, our full path will contain the drive letter, thus:

I:\Fantasy

For Linux, our full path must be relative to the root directory, thus:

/media/leon/DEFILER_MOVIES/Fantasy

Please note: Comparison of the above paths may make it seem that the Windows way is more efficient. However, remember that one may mount storage in any directory where the user has access. For example, all home directories on the UFS HPC is actually contained on a separate storage server on the network. Again, for the user, there is no way to discern that this is the case during normal use.

The Home directory

Notice that it has been emphasized user access to a particular directory when we discussed manual mounting of storage devices. This is because Linux only grants full read and write access to a normal user within that user's home directory.

Outside of this directory the user can have read permissions (to access programs that need to run), but they are unable to make changes to any directory or file. This is a deliberate design choice for security reasons. Without write permissions, malicious actors or programs cannot affect the rest of the system. This is one of the reasons why malware on Linux are rare.

All user home directories are mounted under /home/. Thus, for the user with the user name "leon" the full path to this user's home directory will be /home/leon/

Files

Files handling are largely similar between Windows and Linux. The only major difference is the importance of file extensions. In Linux the importance of file extensions are largely de-emphasized, as even within Windows, the file extension is more of a human readable label to inform one of which program to use the file with. Thus, in Linux, users will often encounter text files with no extension.