Determine file system timestamp precision

filesystemstimestamps

File timestamps precision is limited to one second for EXT3, one microsecond for UFS, and one nanosecond for EXT4 (at least according to experience). Is there any way to determine this based only on filesystem info?

The hacky alternatives I can think of are either to limit all my unit tests to seconds (which I do now), or to touch a bunch of files and checking which digits are zero in stat -c %x.

Best Answer

As far as I know, there is no place that this information is stored on. It is coded into the filesystem. However, you can manually make a list of filesystems and the corresponding precision. I would use a case statement to test the filesystem id against your list of filesystems. You can make the default 1 since there are very few examples where precision is less than 1 second.

Older versions of FAT and current versions of zip use 2-second timestamp precision from what I have read online. However, I suggest you fact-check that.

You can get the id of a file's filsystem with the following command.

stat -f --format="%t" $file
Related Question