- 10 basic & powerful commands to check file system type in Linux/Unix
- What is a FileSystem?
- Commands to check file system type in Linux or Unix
- 1. blkid
- 2. lsblk
- 3. df
- 4. findmnt
- 5. file
- 6. udevadm
- 7. File /etc/fstab content
- 8. File /etc/mtab content
- 9. File /proc/mounts
- 10. mount command
- 4 Commands to List Mounted File Systems in Linux
- 1. View Linux Mounted Filesystem Using /proc Filesystem
- 2. List Linux Mounted Filesystem Using df Command
- 3. Print Linux Mounted Filesystems Using findmnt Command
- 4. Show Mounted Linux Filesystem Using mount Command
10 basic & powerful commands to check file system type in Linux/Unix
Any operating system must be able to access and manage files on storage devices; however, the manner in which the files are organized on a storage device is actually set by the underlying filesystem.With Linux and Unix there are various filesystem types, so in this article I will share multiple commands and methods to check file system type in Linux and Unix.
Before we try to determine and check file system type, we must be familiar with the term «File System».
What is a FileSystem?
As you probably know, or at least can guess, hard drives are not monolithic entities with data simply spread haphazardly around the hard drive. Hard drives are organized into sectors and clusters. Data of any type is organized into files. Whether it is a document, image, spreadsheet, or even an executable program, it is a file. That file may be stored in one or more clusters.
Filesystems are responsible to organize, find, and work with those files that are on the hard drive. There are issues that any filesystem must address in order to handle files effectively.
The first issue occurs because many files are larger than a single sector or cluster. So, locating the entirety of a file on a hard drive is an issue that must be addressed. The operating system may need to check several clusters, not necessarily contiguous, to find a file.
Another problem is how to store the files in clusters and sectors. Also, a filesystem must address how to handle space left due to deleted or moved files.
Now since we know what is a File System, Let us start with the actual agenda of this article.
Commands to check file system type in Linux or Unix
1. blkid
blkid can determine the type of content (e.g. filesystem or swap) that a block device holds, and also the attributes (tokens, NAME=value pairs) from the content metadata (e.g. LABEL or UUID fields).
You can also create your own man page with a list of instructions for a script or a custom tool which you have created. In real time production environment it is always recommended to also create and release a man page for every script or tool we develop.
You must execute blkid as root user without any directives and check » TYPE » field to check file system type of respective partition or device in Linux or Unix.
[root@centos-8 ~]# blkid /dev/mapper/rhel-root: UUID="0b5322d5-887d-4c03-9933-b75c2a1ca880" TYPE="ext4" /dev/sda2: UUID="pXZ2Iy-hwtF-mFH2-nbej-0Yz9-Py2O-AqLQNH" TYPE="LVM2_member" PARTUUID="fcbab19d-02" /dev/sdb1: UUID="1b3910d9-11a9-4f68-894e-47a51bd077a8" TYPE="crypto_LUKS" PARTUUID="09181a39-01" /dev/sda1: UUID="2b857500-a7cf-4ec4-8453-0ef636943d86" TYPE="ext4" PARTUUID="fcbab19d-01" /dev/sr0: UUID="2019-08-15-21-52-52-00" LABEL="CentOS-8-BaseOS-x86_64" TYPE="iso9660" PTUUID="3e04f576" PTTYPE="dos" /dev/mapper/rhel-swap: UUID="cd18aa4a-e2d3-423c-b120-7fef1b1d9aac" TYPE="swap"
With -t, —match-token NAME=value , you can search for block devices with tokens named NAME that have the value value, and display any devices which are found. Common values for NAME include TYPE , LABEL , and UUID
For example to list and check file system type for ext4 FS:
[root@centos-8 ~]# blkid -t TYPE=ext4 /dev/mapper/rhel-root: UUID="0b5322d5-887d-4c03-9933-b75c2a1ca880" TYPE="ext4" /dev/sda1: UUID="2b857500-a7cf-4ec4-8453-0ef636943d86" TYPE="ext4" PARTUUID="fcbab19d-01"
2. lsblk
lsblk lists information about all available or the specified block devices. lsblk command provides more information, better control on output formatting, easy to use in scripts and it does not require root permissions to get actual information.
[root@centos-8 ~]# lsblk --fs NAME FSTYPE LABEL UUID MOUNTPOINT sda ├─sda1 ext4 2b857500-a7cf-4ec4-8453-0ef636943d86 /boot └─sda2 LVM2_member pXZ2Iy-hwtF-mFH2-nbej-0Yz9-Py2O-AqLQNH ├─rhel-root ext4 0b5322d5-887d-4c03-9933-b75c2a1ca880 / └─rhel-swap swap cd18aa4a-e2d3-423c-b120-7fef1b1d9aac [SWAP] sdb └─sdb1 crypto_LUKS 1b3910d9-11a9-4f68-894e-47a51bd077a8 sr0 iso9660 CentOS-8-BaseOS-x86_64 2019-08-15-21-52-52-00 sr1
3. df
df is another popular and most used command to display the amount of disk space available on the file system containing each file name argument. If no file name is given, the space available on all currently mounted file systems is shown.
Using -T directive with df command you can print file system type of all the mounted file systems.
[root@centos-8 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 2.4G 0 2.4G 0% /dev tmpfs tmpfs 2.4G 0 2.4G 0% /dev/shm tmpfs tmpfs 2.4G 8.6M 2.4G 1% /run tmpfs tmpfs 2.4G 0 2.4G 0% /sys/fs/cgroup /dev/mapper/rhel-root ext4 14G 9.2G 3.5G 73% / /dev/sda1 ext4 488M 129M 325M 29% /boot tmpfs tmpfs 479M 0 479M 0% /run/user/0
Alternatively you can specify a device with df command to check file system type of the respective device
# df -Th /boot /dev/sda1 ext4 488M 129M 325M 29% /boot
4. findmnt
findmnt will list all mounted filesystems or search for a filesystem. The findmnt command is able to search in /etc/fstab , /etc/mtab or /proc/self/mountinfo . If device or mountpoint is not given, all filesystems are shown.
Using —fstab directive, findmnt command will search in /etc/fstab and with -t it will limit the set of printed filesystems
[root@centos-8 ~]# findmnt --fstab -t ext4 TARGET SOURCE FSTYPE OPTIONS / /dev/mapper/rhel-root ext4 defaults /boot UUID=2b857500-a7cf-4ec4-8453-0ef636943d86 ext4 defaults
If used without any directive, findmnt command will give you long list of output with all bind mounts
[root@centos-8 ~]# findmnt -t ext4 TARGET SOURCE FSTYPE OPTIONS / /dev/mapper/rhel-root ext4 rw,rela ├─/boot /dev/sda1 ext4 rw,rela ├─/var/named/chroot/etc/localtime /dev/mapper/rhel-root[/usr/share/zoneinfo/Asia/Kolkata] │ ext4 rw,rela ├─/var/named/chroot/etc/named.root.key /dev/mapper/rhel-root[/etc/named.root.key] ext4 rw,rela ├─/var/named/chroot/etc/named.conf /dev/mapper/rhel-root[/etc/named.conf] ext4 rw,rela ├─/var/named/chroot/etc/named.rfc1912.zones /dev/mapper/rhel-root[/etc/named.rfc1912.zones] ext4 rw,rela ├─/var/named/chroot/etc/rndc.key /dev/mapper/rhel-root[/etc/rndc.key] ext4 rw,rela ├─/var/named/chroot/etc/crypto-policies/back-ends/bind.config │ /dev/mapper/rhel-root[/usr/share/crypto-policies/DEFAULT/bind.txt] │ ext4 rw,rela ├─/var/named/chroot/etc/protocols /dev/mapper/rhel-root[/etc/protocols] ext4 rw,rela ├─/var/named/chroot/etc/services /dev/mapper/rhel-root[/etc/services] ext4 rw,rela ├─/var/named/chroot/etc/named /dev/mapper/rhel-root[/etc/named] ext4 rw,rela ├─/var/named/chroot/usr/lib64/bind /dev/mapper/rhel-root[/usr/lib64/bind] ext4 rw,rela └─/var/named/chroot/var/named /dev/mapper/rhel-root[/var/named] ext4 rw,rela
5. file
file command is normally only attempts to read and determine the type of argument files. Specifying the -s option causes file to also read argument files which are block or character special files. This is useful for determining and to check file system types of the data in raw disk partitions, which are block special files
# file -s /dev/sda1 /dev/sda1: Linux rev 1.0 ext4 filesystem data, UUID=2b857500-a7cf-4ec4-8453-0ef636943d86 (needs journal recovery) (extents) (64bit) (large files) (huge files)
6. udevadm
udevadm command queries the udev database for device information stored in the udev database. It can also query the properties of a device from its sysfs representation to help creating udev rules that match this device.
Using —query you can query the database for the specified type of device data. The below command gives a long output so we will grep the required data to check file system type for our device /dev/sda1
# udevadm info --query=property /dev/sda1 | egrep "DEVNAME|ID_FS_TYPE" DEVNAME=/dev/sda1 ID_FS_TYPE=ext4
Some more commands and methods to determine filesystem type in Linux or Unix
Now above were some of the most used commands to check file system type but there are many other methods using which you can determine filesystem type
7. File /etc/fstab content
Normally all the devices we use are mounted via /etc/fstab file to make the mounting reboot persistent. So you can always refer /etc/fstab file to check file system type, for example:
# cat /etc/fstab /dev/mapper/rhel-root / ext4 defaults 1 1 UUID=2b857500-a7cf-4ec4-8453-0ef636943d86 /boot ext4 defaults 1 2 /dev/mapper/rhel-swap swap swap defaults 0 0
Here the first column of the file specifies the partition device path while the third column shows the file system type of the respective device.
8. File /etc/mtab content
Similar to /etc/fstab you can also refer /etc/mtab to get the list of currently mounted file system along with the file system type.
# grep root /etc/mtab /dev/mapper/rhel-root / ext4 rw,relatime 0 0
Here also the first column of the file specifies the partition device path while the third column shows the file system type of the respective device.
9. File /proc/mounts
Now /proc/mounts file refers /etc/mtab so this is not a new method but just another file which you can look into to check file system type in Linux or Unix.
10. mount command
Again, mount command will also refer /etc/mtab file to get the list of mounted file systems and can also help you determine file system type of individual devices.
# mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) devtmpfs on /dev type devtmpfs (rw,nosuid,size=2436780k,nr_inodes=609195,mode=755) securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
Lastly I hope the methods and commands from the article to determine and check file system type on Linux and Unix was helpful. So, let me know your suggestions and feedback using the comment section.
Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud
If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.
For any other feedbacks or questions you can either use the comments section or contact me form.
Thank You for your support!!
4 Commands to List Mounted File Systems in Linux
The Linux operating system provides multiple filesystems, including ext4, xfs, tmpfs, securityfs, and many more. This guide demonstrates various ways to list all mounted file systems in a Linux system.
1. View Linux Mounted Filesystem Using /proc Filesystem
The /proc/mounts file is a file that displays the status of all filesystems that are currently mounted on the system. The file format closely resembles that of the /etc/fstab file. The file reports the status of mounted filesystems as recorded by the Linux kernel.
Thus, to view all the mounted filesystems, view the /proc/mounts file using the cat command as shown.
2. List Linux Mounted Filesystem Using df Command
The df command is mostly used to check disk space utilization on mounted file systems. It lists, among other statistics, total disk space and available disk space on each mounted filesystem.
When the -a option is included, the df command lists all the mounted filesystems.
3. Print Linux Mounted Filesystems Using findmnt Command
The findmnt command is yet another powerful command that displays all mounted filesystems on your Linux system in a tree-like format.
To print all the mounted filesystems, simply run the command without any arguments.
This prints the output in a tree-like format as shown.
You can pass the -D option which will print the output similar to the df -Th command
Pass the -t option followed by the filesystem type to print specific filesystems. For example, to view all the mounted EXT4 filesystems, run the command:
To view all EXT4 filesystems mounted in the /etc/fstab file, run the command:
4. Show Mounted Linux Filesystem Using mount Command
You can also use the mount command to list all mounted file systems. Without any arguments, it lists all the mounted filesystems.
Summing Up
In this guide, we have explored four ways that you can use to list all mounted file systems in a Linux system. Your views and feedback on this guide are welcome.