How to determine, with certainty, the filesystem type of a partition from the outputs of the Linux "file -s" command?
3
votes
3
answers
879
views
My problem is to *decode* the output of the command
file -s /dev/sdX
on my system (where /dev/sdX
is the device file associated to a USB key).
Below I'll show the output of the command file -s /dev/sdX
where the device file /dev/sda1
is a partition formatted with a FAT32
filesystem, while the device /dev/sdb
is a partition formatted with a NTFS
filesystem.
### Output of file
command for a FAT32
filesystem ###
In the case of the FAT32
filesystem the output of the file
command is:
> file -s /dev/sda1
/dev/sda1: DOS/MBR boot sector, code offset 0x58+2, OEM-ID "mkfs.fat", sectors/cluster 8, Media descriptor 0xf8, sectors/track 62, heads 31, hidden sectors 2048, sectors 1966080 (volumes > 32 MB), FAT (32 bit), sectors/FAT 1920, reserved 0x1, serial number 0x4ba3ff5b, unlabeled
In the output is present the information , FAT (32 bit), sectors/FAT 1920,
which could be enough to say that the filesystem type is FAT32, but in the next paragraph I'll show that the string FAT
is also present in the output of the file
command in the case of an NTFS
filesystem.
### Output of file
command for a NTFS
filesystem ###
In the case of a NTFS
filesystem the output of the file
command is:
> file -s /dev/sdb
/dev/sdb: DOS/MBR boot sector, code offset 0x52+2, OEM-ID "NTFS ", sectors/cluster 8, Media descriptor 0xf8, sectors/track 63, heads 255, dos file -s /dev/sdf
/dev/sdf: DOS/MBR boot sector
In this case exfat
is not present in the output.
### Output of file
for ext4
###
file -s /dev/sdb1
/dev/sdb1: Linux rev 1.0 ext4 filesystem data, UUID=38bc3d5b-381e-4f19-8640-c77d9483882b (needs journal recovery) (extents) (64bit) (large files) (huge files)
In this case is present the info ext4 filesystem data,
.
In these 4 examples (FAT32, NTFS, EXFAT, EXT4) the output of the file
command appears very different for different filesystem types, so it is difficult to find a simple rule to decide the filesystem type by this output.
___
**EDIT**
To clarify why I'm trying to use the file
command *to get information about the filesystem type of a USB*, please read [this post](https://unix.stackexchange.com/questions/794029/how-to-find-the-filesystem-type-of-the-partition-of-an-usb-before-mount-it) .
Asked by User051209
(498 rep)
Apr 22, 2025, 04:00 PM
Last activity: Apr 24, 2025, 03:24 PM
Last activity: Apr 24, 2025, 03:24 PM