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 < 4.0 BootSector (0x0), FAT (1Y bit by descriptor); NTFS, sectors/track 63, physical drive 0x80, sectors 15654911, $MFT start cluster 786432, $MFTMirror start cluster 2, bytes/RecordSegment 2^(-1*246), clusters/index block 1, serial number 030fcd5a9fcd56a1c; contains bootstrap BOOTMGR In this output is present the information ; NTFS, but it is also present the string FAT.
The question
From the previous outputs of the file -s command, how to determine the filesystem of the two partitions with certainty?
EDIT[1]
I add the output of the file -s command for a exfat partition and for an ext4 partition.
Output of file for exfat
> 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[2]
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.
filefor this? As you show very nicely, it isn't the best tool for the job. Does this absolutely have to be done usingfile? There are several better options iffileisn't a hard requirement. Also, what system(s) does this need to work on?--keep-goingoption to yourfilecommand, or seeman fdisk stat/dev/sdband/dev/sdf) and on partitions (/dev/sda1), is this intended?/dev/sdaor/dev/sda1device for my goal. The answer of @terdon for me is perfectfileis a tool for guessing.