Does the hash of a file change if the filename or path or timestamp or permissions change?
$ echo some contents > testfile
$ shasum testfile
3a2be7b07a1a19072bf54c95a8c4a3fe0cdb35d4 testfile
The hash of a file is the hash of its contents. Metadata such as the file name, timestamps, permissions, etc. have no influence on the hash.
Assuming a non-broken cryptographic hash, two files have the same hash if and only if they have the same contents. The most common such hashes are the SHA-2 family (SHA-256, SHA-384, SHA-512) and the SHA3 family. This does not include MD5 or SHA-1 which are broken, nor a CRC such as with cksum
which is not a cryptographic hash.
Not as far as I can tell after a simple test.
$ echo some contents > testfile
$ shasum testfile
3a2be7b07a1a19072bf54c95a8c4a3fe0cdb35d4 testfile
$ mv testfile newfile
$ shasum newfile
3a2be7b07a1a19072bf54c95a8c4a3fe0cdb35d4 newfile
shasum
, they will not match since the output includes the filename/path (as shown in your example). A good workaround is to do something like shasum - < testfile
.
– DoxyLover
Aug 03 '15 at 22:53
zip
it. – ctrl-alt-delor Aug 03 '15 at 22:48