In Linux (currently using ext4 filesystem), how can one check quickly if the contents of a file has been modified without reading any of its contents?
Is the stat
command a recommended approach? I currently do
$ stat --format "%Y" hello.txt
and later I can check if the same command yields the same output. If it does, I conclude that hello.txt has not changed.
My feeling is that one wants to throw in more parameters to be even more sure. For example, would adding the file size, file name, etc, provide an even better "fingerprint" of the file?
On this topic, I recall that a TrueCrypt volume I once had was always ignored by my incremental backup program, possibly because TrueCrypt made sure to leave no meta data changes behind. I suppose it is indeed possible to change all the data returned by stat
, hence it cannot be guaranteed to pick up on every possible modification of the file?
md5sum filename
?md5sum
or any sort of checksum reads the contents of the file. I do not want to do that as it is way too slow for my purposes.ls -t
will sort the contents in a directory by modification time.