File Management

Ways to Determine the File System Type in Linux

In computing, a filesystem is a layout or format used to store files in a storage device. A filesystem is used to logically divide a storage device to keep different files organized nicely in the storage device to be searched, accessed, modified, removed, etc. easily from the storage device.

There are many filesystems available today. Different filesystems have different structures, logics, features, flexibility, security, etc. Some of the most common filesystems are Ext4, Btrfs, XFS, ZFS, NTFS, FAT32, etc.

There are times when a Linux system administrator will need to determine the filesystem type to simply mount the filesystem or to diagnose problems with the filesystem. Different filesystems have different tools for diagnosing problems, checking for errors and fixing them, etc. So, you have to know the filesystem a storage device is using to determine the maintenance tool/tools to use.

In this article, I will show you different ways you can determine the filesystem type in Linux. So, let’s get started.

Way 1: Using the df Command-Line Tool

The df command-line program is preinstalled on almost every Linux distribution you will find. You can use the df command-line program to find the Filesystem type all the mounted storage devices and partitions.

To find the filesystem type of all the mounted storage devices and partitions of your computer, run the df command as follows:

$ df -Th

The df command will show you the following information:
Filesystem: The storage device name or partition name that is currently mounted.

Mounted on: The directory where the storage device/partition (Filesystem) is mounted.

Type: The filesystem type of the mounted storage device/partition.

Size: The size of the mounted storage device/partition.

Used: The disk space that is used from the mounted storage device/partition.

Use%: The percentage of disk space that is used from the mounted storage device/partition.

Avail: The amount of free disk space of the mounted storage device/partition.

On Ubuntu, the df command will show you many loop devices as you can see in the screenshot below.

You can hide the loop devices with the -x option of the df command as follows:

$ df -Th -x squashfs

You can also hide the tmpfs devices from the output of the df command.

To hide the tmpfs devices from the output of the df command as well, run the df command with the -x option as follows:

$ df -Th -x squashfs -x tmpfs

Now, the output looks much cleaner. If you want, you can remove the udev devices from the df command’s output.

To remove the udev devices from the output of the df command as well, run the df command as follows:

$ df -Th -x squashfs -x tmpfs -x devtmpfs

Only the physical storage devices and partitions will be displayed in the output of the df command. The output looks much nicer than before as well.

Way 2: Using the lsblk Command

The lsblk command-line program is preinstalled on almost every Linux distribution you will find. You can use the lsblk command-line program to find the Filesystem type of all (mounted and unmounted) the storage devices and partitions of your computer.

To find the filesystem type of all (mounted and unmounted) the storage devices and partitions of your computer, run the lsblk command as follows:

$ lsblk -f

The lsblk command will show you the following information:
NAME: The storage device name or partition name of a storage device.

MOUNTPOINT: The directory where the storage device/partition (Filesystem) is mounted (if mounted).

FSTYPE: The filesystem type of the storage device/partition.

LABEL: The filesystem label of the storage device/partition.

UUID: The UUID (Universally Unique IDentifier) of the filesystem of the storage device/partition.

FSUSE%: The percentage of disk space that is used from the storage device/partition.

FSAVAIL: The amount of free disk space of the storage device/partition

Just as before, you can hide the loop devices from the output of the lsblk command.

To hide the loop devices from the output of the lsblk command, run the lsblk command with the -e7 option as follows:

$ lsblk -f -e7

As you can see, all the loop devices are removed from the output of the lsblk command. The output looks a lot cleaner than before.

Way 3: Using the blkid Command

The blkid command-line program is preinstalled on almost every Linux distribution you will find. You can use the blkid command-line program to find the Filesystem type of all (mounted and unmounted) the storage devices and partitions of your computer.

To find the filesystem type of all (mounted and unmounted) the storage devices and partitions of your computer, run the blkid command as follows:

$ blkid

The lsblk command will show you the following information:
NAME: The name of the storage device or partition name of the storage device. i.e. /dev/sda1, /dev/sda5.

UUID: The UUID (Universally Unique IDentifier) of the filesystem of the storage device/partition.

TYPE: The filesystem type of the storage device/partition.

PARTUUID: The UUID (Universally Unique IDentifier) of the partition.

You can also hide the loop devices from the output of the blkid command as before.

To hide the loop devices from the output of the blkid command, run the blkid command as follows:

$ blkid | grep -v 'TYPE="squashfs"'

As you can see, the loop devices are not displayed in the output of the blkid command. The output looks much nicer than before.

Way 4: Using the file Command

The file command-line program is preinstalled on almost every Linux distribution you will find. You can use the find command-line program to identify the file type of a file on Linux. As every device is considered a file in Linux, you can use the find command-line program to determine the filesystem type of a storage device or partition in Linux.

For example, to determine the filesystem type of the partition sdb1, you can run the file command as follows:

$ sudo file -sL /dev/sda1

If you read the file command’s output, you can see that the sdb1 partition is using the FAT32 filesystem.

In the same way, you can find the filesystem type of the sda5 partition with the file command as follows:

$ sudo file -sL /dev/sda5

As you can see, the partition sda5 is using the EXT4filesystem.

Way 5: Using the mount Command and /etc/mtab File

The /etc/mtab file contains an entry for all the mounted storage devices and partitions of your computer. You can read this file to find the filesystem type of your storage devices and partitions. The mount command-line program also prints the contents of the /etc/mtab file. So, you can use the mount command-line program as well to find the same data.

You can read the contents of the /etc/mtab file with the following command:

$ sudo /etc/mtab

As you can see, there is a lot of mount information in the /etc/mtab file.

You can find the same information with the mount command as you can see in the screenshot below.

$ mount

As the /etc/mtab file or the mount command’s output has many mount entries, it’s hard to interpret it. You can use the grep command to filter the output and find what you need very easily.

For example, to find the filesystem type of the sda1 partition using either the mount command or /etc/mtab file, run one of the following commands:

$ cat /etc/mtab | grep /dev/sda1

Or,

$ mount | grep /dev/sda1

As you can see, the filesystem type of the sda1 partition is FAT32/vfat

.

In the same way, to find the filesystem type of the sda5 partition using either the mount command or /etc/mtab file, run one of the following commands:

$ cat /etc/mtab | grep /dev/sda5

Or,

$ mount | grep /dev/sda5

As you can see, the filesystem type of the sda5 partition is EXT4.

Way 6: Using the /etc/fstab File

The /etc/fstab file keeps an entry for each of the storage devices or partitions that is to be mounted automatically at boot time. So, you can read this file to find the filesystem type of your desired storage device or partition.

Suppose your computer is not configured to mount a storage device or partition at boot time automatically. In that case, it’s very likely that there won’t be any entry for that storage device or partition in the /etc/fstab file. In that case, you won’t find any information on that storage device or partition in the /etc/fstab file. You will have to use the other methods described in this article to find the storage device’s filesystem type or partition.

You can read the contents of the /etc/fstab file with the following command:

$ cat /etc/fstab

The contents of the /etc/fstab file.

You can see that the storage device or partition with the UUID 3f962401-ba93-46cb-ad87-64ed6cf55a5f uses the EXT4 filesystem.

The storage device or partition that has the UUID dd55-ae26 is using the vfat/FAT32 filesystem.

The lines starting with a # in the /etc/fstab file is a comment. These lines don’t have a real purpose. They are used for documentation purposes only.

If you want, you can hide them using the grep command as follows:

$ grep -v '^#' /etc/fstab

As you can see, the comments are gone, and the output looks a lot cleaner than before.

The /etc/fstab file uses UUID instead of the storage device name or partition name by default. You can use the blkid command to convert the UUID to storage device name or partition name.

For example, to convert the UUID 3f962401-ba93-46cb-ad87-64ed6cf55a5f to the name of the storage device or partition, run the blkid command as follows:

$ blkid -U 3f962401-ba93-46cb-ad87-64ed6cf55a5f

As you can see, the partition sda5 has the UUID 3f962401-ba93-46cb-ad87-64ed6cf55a5f.

In the same way, you can find the storage device or partition name that has the UUID DD55-AE26 as follows:

$ blkid -U DD55-AE26

As you can see, the partition sda1 has the UUID DD55-AE26.

Conclusion:

This article has shown you different ways to determine the filesystem type of a storage device/partition in Linux. I have shown you how to use the df, lsblk, blkid, file, and mount command to determine the filesystem type of the Linux storage devices and partitions. I have also shown you how to determine the filesystem type of the storage devices and partitions of your Linux system by reading the /etc/mtab and /etc/fstab files.

References:

[1] File system – Wikipedia – https://en.wikipedia.org/wiki/File_system

About the author

Shahriar Shovon

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.