Checking the filesystem of storage devices on Linux

A filesystem divides a storage device into logical sections. This helps keep files well-organized for performing various operations like searching, modifying, or deleting files from the device. There are various types of filesystems in existence today, some of these include FAT32, NTFS, Ext4, ZFS, etc. Most OSes provide a way to discover the filesystem being used on a storage device. On the Linux OS, there are multiple ways to discover the filesystem being used. Two of the ways to do this include:

  1. By using the df command-line tool

  2. By using the file command

Using the df command-Line Tool

The df command-line tool shows the type of filesystem being used by all mounted storage devices on the system. It comes preinstalled with the majority of Linux distributions. The following screenshots show how the filesystem type can be checked using the df command-line tool:

In the screenshot above, the df command is issued along with the -Th flag. The T flag shows the type of filesystem while the h flag displays the size in human-readable format. This lists the filesystem of all the mounted devices including the type (Type), size of the device (Size), amount of device storage used (Used), amount of device storage available (Avail), percentage of used space (Use%), and path where the mounted device can be found (Mounted on).

Using the file command

Like the df command-line tool, the file command-line program comes preinstalled with most Linux distributions. On the Linux OS, everything is considered to be a file. Hence, the storage devices mounted on the system can be considered as files, and with the help of the file command, we can discover which filesystem is being used by the storage device. However, unlike the df command which lists all storage devices, the file command takes a specific storage device as an argument and tells us the filesystem being used.

The file command requires permission to be run, so I switched to root user mode to execute the command. In the screenshot above, we can see that the filesystem for the device /dev/sda3 is ext4 which corresponds to the same information we got when we ran the df command. The command is executed with the -sL flags which stand for special-files and dereference, respectively.