Does the hash of a file change if the filename changes?












4















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









share|improve this question


















  • 1





    If you need it to, then you can zip it.

    – ctrl-alt-delor
    Aug 3 '15 at 22:48
















4















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









share|improve this question


















  • 1





    If you need it to, then you can zip it.

    – ctrl-alt-delor
    Aug 3 '15 at 22:48














4












4








4


1






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









share|improve this question














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






hashsum






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 3 '15 at 22:41









tarabytetarabyte

1,00251832




1,00251832








  • 1





    If you need it to, then you can zip it.

    – ctrl-alt-delor
    Aug 3 '15 at 22:48














  • 1





    If you need it to, then you can zip it.

    – ctrl-alt-delor
    Aug 3 '15 at 22:48








1




1





If you need it to, then you can zip it.

– ctrl-alt-delor
Aug 3 '15 at 22:48





If you need it to, then you can zip it.

– ctrl-alt-delor
Aug 3 '15 at 22:48










2 Answers
2






active

oldest

votes


















7














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.






share|improve this answer





















  • 1





    In general, all hashes have collisions. A non-broken cryptographic hash implies that there is no efficient way to generate a collision.

    – Tyson Williams
    Jan 23 at 15:29











  • @TysonWilliams That's true but irrelevant. If you have two files with the same hash, and the hash is a non-broken cryptographic hash, then the two files have the same hash if and only if they have the same contents. If you could find a collision, it wouldn't be a non-broken cryptographic hash.

    – Gilles
    Jan 23 at 22:23






  • 1





    What you said is false. Every (practical) hash function, even non-broken cryptographic ones, have collisions. There are more inputs than outputs, so by the pigeonhole principle, there must be a collision.

    – Tyson Williams
    Jan 23 at 22:29













  • @TysonWilliams But I never claimed that there were no collisions. Of course there are collisions. But 1. it's extremely rare to find collisions for what is generally considered to be a non-broken cryptographic hash function, and 2. if someone did find a collision then that function would no longer be a non-broken cryptographic hash function. In practical terms, if you have two files with the same SHA-256 hash, they have identical contents.

    – Gilles
    Jan 23 at 22:33






  • 1





    The statement "f you have two files with the same hash, and the hash is a non-broken cryptographic hash, then the two files have the same hash if and only if they have the same contents." is equivalent to "non-broken cryptographic hash [functions] have no collisions". I agree that "In practical terms, if you have two files with the same SHA-256 hash, they have identical contents."

    – Tyson Williams
    Jan 23 at 22:36



















4














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





share|improve this answer



















  • 1





    But note that if you blindly compare the outputs of 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 3 '15 at 22:53











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f220017%2fdoes-the-hash-of-a-file-change-if-the-filename-changes%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









7














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.






share|improve this answer





















  • 1





    In general, all hashes have collisions. A non-broken cryptographic hash implies that there is no efficient way to generate a collision.

    – Tyson Williams
    Jan 23 at 15:29











  • @TysonWilliams That's true but irrelevant. If you have two files with the same hash, and the hash is a non-broken cryptographic hash, then the two files have the same hash if and only if they have the same contents. If you could find a collision, it wouldn't be a non-broken cryptographic hash.

    – Gilles
    Jan 23 at 22:23






  • 1





    What you said is false. Every (practical) hash function, even non-broken cryptographic ones, have collisions. There are more inputs than outputs, so by the pigeonhole principle, there must be a collision.

    – Tyson Williams
    Jan 23 at 22:29













  • @TysonWilliams But I never claimed that there were no collisions. Of course there are collisions. But 1. it's extremely rare to find collisions for what is generally considered to be a non-broken cryptographic hash function, and 2. if someone did find a collision then that function would no longer be a non-broken cryptographic hash function. In practical terms, if you have two files with the same SHA-256 hash, they have identical contents.

    – Gilles
    Jan 23 at 22:33






  • 1





    The statement "f you have two files with the same hash, and the hash is a non-broken cryptographic hash, then the two files have the same hash if and only if they have the same contents." is equivalent to "non-broken cryptographic hash [functions] have no collisions". I agree that "In practical terms, if you have two files with the same SHA-256 hash, they have identical contents."

    – Tyson Williams
    Jan 23 at 22:36
















7














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.






share|improve this answer





















  • 1





    In general, all hashes have collisions. A non-broken cryptographic hash implies that there is no efficient way to generate a collision.

    – Tyson Williams
    Jan 23 at 15:29











  • @TysonWilliams That's true but irrelevant. If you have two files with the same hash, and the hash is a non-broken cryptographic hash, then the two files have the same hash if and only if they have the same contents. If you could find a collision, it wouldn't be a non-broken cryptographic hash.

    – Gilles
    Jan 23 at 22:23






  • 1





    What you said is false. Every (practical) hash function, even non-broken cryptographic ones, have collisions. There are more inputs than outputs, so by the pigeonhole principle, there must be a collision.

    – Tyson Williams
    Jan 23 at 22:29













  • @TysonWilliams But I never claimed that there were no collisions. Of course there are collisions. But 1. it's extremely rare to find collisions for what is generally considered to be a non-broken cryptographic hash function, and 2. if someone did find a collision then that function would no longer be a non-broken cryptographic hash function. In practical terms, if you have two files with the same SHA-256 hash, they have identical contents.

    – Gilles
    Jan 23 at 22:33






  • 1





    The statement "f you have two files with the same hash, and the hash is a non-broken cryptographic hash, then the two files have the same hash if and only if they have the same contents." is equivalent to "non-broken cryptographic hash [functions] have no collisions". I agree that "In practical terms, if you have two files with the same SHA-256 hash, they have identical contents."

    – Tyson Williams
    Jan 23 at 22:36














7












7








7







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 23 at 22:25

























answered Aug 4 '15 at 1:09









GillesGilles

534k12810791597




534k12810791597








  • 1





    In general, all hashes have collisions. A non-broken cryptographic hash implies that there is no efficient way to generate a collision.

    – Tyson Williams
    Jan 23 at 15:29











  • @TysonWilliams That's true but irrelevant. If you have two files with the same hash, and the hash is a non-broken cryptographic hash, then the two files have the same hash if and only if they have the same contents. If you could find a collision, it wouldn't be a non-broken cryptographic hash.

    – Gilles
    Jan 23 at 22:23






  • 1





    What you said is false. Every (practical) hash function, even non-broken cryptographic ones, have collisions. There are more inputs than outputs, so by the pigeonhole principle, there must be a collision.

    – Tyson Williams
    Jan 23 at 22:29













  • @TysonWilliams But I never claimed that there were no collisions. Of course there are collisions. But 1. it's extremely rare to find collisions for what is generally considered to be a non-broken cryptographic hash function, and 2. if someone did find a collision then that function would no longer be a non-broken cryptographic hash function. In practical terms, if you have two files with the same SHA-256 hash, they have identical contents.

    – Gilles
    Jan 23 at 22:33






  • 1





    The statement "f you have two files with the same hash, and the hash is a non-broken cryptographic hash, then the two files have the same hash if and only if they have the same contents." is equivalent to "non-broken cryptographic hash [functions] have no collisions". I agree that "In practical terms, if you have two files with the same SHA-256 hash, they have identical contents."

    – Tyson Williams
    Jan 23 at 22:36














  • 1





    In general, all hashes have collisions. A non-broken cryptographic hash implies that there is no efficient way to generate a collision.

    – Tyson Williams
    Jan 23 at 15:29











  • @TysonWilliams That's true but irrelevant. If you have two files with the same hash, and the hash is a non-broken cryptographic hash, then the two files have the same hash if and only if they have the same contents. If you could find a collision, it wouldn't be a non-broken cryptographic hash.

    – Gilles
    Jan 23 at 22:23






  • 1





    What you said is false. Every (practical) hash function, even non-broken cryptographic ones, have collisions. There are more inputs than outputs, so by the pigeonhole principle, there must be a collision.

    – Tyson Williams
    Jan 23 at 22:29













  • @TysonWilliams But I never claimed that there were no collisions. Of course there are collisions. But 1. it's extremely rare to find collisions for what is generally considered to be a non-broken cryptographic hash function, and 2. if someone did find a collision then that function would no longer be a non-broken cryptographic hash function. In practical terms, if you have two files with the same SHA-256 hash, they have identical contents.

    – Gilles
    Jan 23 at 22:33






  • 1





    The statement "f you have two files with the same hash, and the hash is a non-broken cryptographic hash, then the two files have the same hash if and only if they have the same contents." is equivalent to "non-broken cryptographic hash [functions] have no collisions". I agree that "In practical terms, if you have two files with the same SHA-256 hash, they have identical contents."

    – Tyson Williams
    Jan 23 at 22:36








1




1





In general, all hashes have collisions. A non-broken cryptographic hash implies that there is no efficient way to generate a collision.

– Tyson Williams
Jan 23 at 15:29





In general, all hashes have collisions. A non-broken cryptographic hash implies that there is no efficient way to generate a collision.

– Tyson Williams
Jan 23 at 15:29













@TysonWilliams That's true but irrelevant. If you have two files with the same hash, and the hash is a non-broken cryptographic hash, then the two files have the same hash if and only if they have the same contents. If you could find a collision, it wouldn't be a non-broken cryptographic hash.

– Gilles
Jan 23 at 22:23





@TysonWilliams That's true but irrelevant. If you have two files with the same hash, and the hash is a non-broken cryptographic hash, then the two files have the same hash if and only if they have the same contents. If you could find a collision, it wouldn't be a non-broken cryptographic hash.

– Gilles
Jan 23 at 22:23




1




1





What you said is false. Every (practical) hash function, even non-broken cryptographic ones, have collisions. There are more inputs than outputs, so by the pigeonhole principle, there must be a collision.

– Tyson Williams
Jan 23 at 22:29







What you said is false. Every (practical) hash function, even non-broken cryptographic ones, have collisions. There are more inputs than outputs, so by the pigeonhole principle, there must be a collision.

– Tyson Williams
Jan 23 at 22:29















@TysonWilliams But I never claimed that there were no collisions. Of course there are collisions. But 1. it's extremely rare to find collisions for what is generally considered to be a non-broken cryptographic hash function, and 2. if someone did find a collision then that function would no longer be a non-broken cryptographic hash function. In practical terms, if you have two files with the same SHA-256 hash, they have identical contents.

– Gilles
Jan 23 at 22:33





@TysonWilliams But I never claimed that there were no collisions. Of course there are collisions. But 1. it's extremely rare to find collisions for what is generally considered to be a non-broken cryptographic hash function, and 2. if someone did find a collision then that function would no longer be a non-broken cryptographic hash function. In practical terms, if you have two files with the same SHA-256 hash, they have identical contents.

– Gilles
Jan 23 at 22:33




1




1





The statement "f you have two files with the same hash, and the hash is a non-broken cryptographic hash, then the two files have the same hash if and only if they have the same contents." is equivalent to "non-broken cryptographic hash [functions] have no collisions". I agree that "In practical terms, if you have two files with the same SHA-256 hash, they have identical contents."

– Tyson Williams
Jan 23 at 22:36





The statement "f you have two files with the same hash, and the hash is a non-broken cryptographic hash, then the two files have the same hash if and only if they have the same contents." is equivalent to "non-broken cryptographic hash [functions] have no collisions". I agree that "In practical terms, if you have two files with the same SHA-256 hash, they have identical contents."

– Tyson Williams
Jan 23 at 22:36













4














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





share|improve this answer



















  • 1





    But note that if you blindly compare the outputs of 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 3 '15 at 22:53
















4














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





share|improve this answer



















  • 1





    But note that if you blindly compare the outputs of 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 3 '15 at 22:53














4












4








4







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





share|improve this answer













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






share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 3 '15 at 22:42









tarabytetarabyte

1,00251832




1,00251832








  • 1





    But note that if you blindly compare the outputs of 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 3 '15 at 22:53














  • 1





    But note that if you blindly compare the outputs of 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 3 '15 at 22:53








1




1





But note that if you blindly compare the outputs of 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 3 '15 at 22:53





But note that if you blindly compare the outputs of 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 3 '15 at 22:53


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f220017%2fdoes-the-hash-of-a-file-change-if-the-filename-changes%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to make a Squid Proxy server?

Is this a new Fibonacci Identity?

19世紀