Skip to main content
SysAdmin Shell Scripting Essentials

Linux Get Filesystem Type — Complete CLI Reference, Syntax

linux get filesystem type means identifying the filesystem format (ext4, XFS, btrfs) of a storage device using CLI commands.

df -Th

Tested on Ubuntu 22.04 with Linux 5.15.x; verify against vendor docs for non-Debian distributions or older kernels.

Syntax

# Most common: show filesystem type for all mounted devices
df -Th

# Show filesystem type for a specific device (e.g., /dev/sda1)
lsblk -f /dev/sda1

# Query filesystem type directly from a block device
sudo blkid /dev/sda1

# Check which filesystem type fsck would use (dry-run)
fsck -N /dev/sda1

# Identify filesystem type from raw device data
sudo file -sL /dev/sda1

# View persistent filesystem type info from /etc/fstab
cat /etc/fstab

Options and Flags

Command Flag Type Default Description
df -T Flag Off Print filesystem type (requires -h for human-readable)
df -Th Flag N/A Combine -T and -h for human-readable sizes with type
lsblk -f Flag N/A Display filesystem type, UUID, and label for each device
blkid None N/A N/A Output filesystem type as TYPE="ext4" when run on a device
fsck -N Flag Off Show what fsck would do without actually checking (dry-run, reveals expected type)
file -s Flag Off Read device special file as ordinary file (necessary for block devices)
file -L Flag Off Follow symbolic links (for devices that are symlinks)
See also  PowerShell Scripting Reference: Syntax, Commands, and Best

Usage Examples

Example 1: Quick check of all mounted filesystems

df -Th

Displays every mounted device with its filesystem type, total size, used space, and mount point. Output includes ext4, xfs, btrfs, tmpfs, and vfat. The header row shows Type column. Useful for a fast overview of active filesystems.

Example 2: Determine filesystem type of an unmounted partition

sudo blkid /dev/sdb1
# Output: /dev/sdb1: UUID="..." TYPE="xfs"

blkid probes the raw partition and returns the filesystem type even if not mounted. Use this when recovering a disk or before mounting a new volume. Requires sudo to read block devices.

Example 3: Dry-run with fsck to see expected type

fsck -N /dev/sda3
# Output: [/sbin/fsck.ext4 (1) -- /dev/sda3] fsck.ext4 /dev/sda3

fsck -N does not run the actual check; it prints the fsck variant it would call. This reveals the filesystem type (e.g., fsck.ext4 means ext4). Rely on this when blkid is unavailable or the device is listed in /etc/fstab with a type but the actual content differs.

Troubleshooting & Common Errors

Error Message Root Cause Resolution Command
blkid: /dev/sdb1: No such device Device does not exist or is not attached Check with lsblk; verify device name with ls /dev/sd*
df: 'xxx': No such file or directory Path is not mounted Verify mount point exists or use mount | grep xxx
fsck: fsck.ext4: No such file or directory while trying to open /dev/sda1 Device node missing or kernel driver not loaded Check ls -l /dev/sda1; verify device existence with lsblk
file: /dev/sda1: cannot open (No such device or address) Device not accessible – missing -s flag or incorrect permissions Use sudo file -sL /dev/sda1
df -T: warning: cannot read table of mounted filesystems Permission denied reading /proc/mounts Run with sudo or check /proc/mounts permissions
See also  Export-CSV PowerShell: Syntax, Flags, Exit Codes, Troubleshooting

Frequently Asked Questions

What is the difference between lsblk -f and df -T for displaying filesystem type?

Answer: lsblk -f shows filesystem type for all block devices, including unmounted ones.

lsblk -f lists UUID, LABEL, FSTYPE, and MOUNTPOINT for every block device; useful for unmounted disks. df -T includes usage stats (size, used, avail) only on active mounts. Example:

lsblk -f
df -T /dev/sda1

When should I use df -Th | grep "^/dev" instead of full df -Th to get filesystem type?

Answer: Use this filter to exclude pseudo filesystems (tmpfs, devtmpfs, cgroup) when auditing real storage.

df -Th | grep "^/dev"

Useful in scripts and monitoring to isolate real filesystem types.

How do I fix “mount: unknown filesystem type ‘ext2′” error on modern Linux?

Answer: Install the e2fsprogs package. Use your distribution’s package manager (e.g., apt-get or yum). Also verify the ext2 kernel module is loaded: modprobe ext2.

Does lsblk -f work on all cloud VM instances (AWS, Azure, GCP)?

Answer: Yes, lsblk -f works universally on Linux VM instances in AWS, Azure, GCP, and on-premises. No cloud-specific dependencies exist. Ensure the util-linux package is installed if the command is missing.

What is the fastest way to get the filesystem type of all mounted volumes in a single command?

Answer: Use df -Th | grep "^/dev". This filters out pseudo filesystems and returns only device-based mounts.

df -Th | grep "^/dev"

For a compact format without headers, pipe to column -t.