I'd like to be able to detect when a file is considered different if the data are still the same but the ownership has changed (or the permission, access/creation time, etc...).
Is there a such tool ?
I'd like to be able to detect when a file is considered different if the data are still the same but the ownership has changed (or the permission, access/creation time, etc...).
Is there a such tool ?
As stated in the answer provided by Detect changes in permissions, you can determine the time of permission changes and the actual permissions by using the stat
command.
So something like that should work:
stat -c "%a %Z" file | cat - file | sha1sum
tar -cf - --no-recursion the_file | sha256sum
Notes:
--no-recursion
in case the_file
is of the type directory. I assumed you want to detect changes to the file itself, not to its subdirectories and such.tar
does not store atime. This means the method cannot detect any change in atime of the_file
. On the other hand the sole act of reading the_file
by tar
may update its atime (depending on mount options), so ignoring atime is most likely a good thing.tar
, you will still get some digest (the digest of empty input) and exit status 0 from sha256sum
. See Get exit status of process that's piped to another.tar
stores the path. The method is sensitive not only to the actual name of the file, but primarily to the pathname you provide. E.g. specifying ./the_file
will give you a different digest than the_file
. To reliably detect changes, pick a pathname and stick to it.*sum
tool (e.g. md5sum
). Pick one and stick to it.