Does the hash of a file change if the filename changes?
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
add a comment |
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
1
If you need it to, then you canzip
it.
– ctrl-alt-delor
Aug 3 '15 at 22:48
add a comment |
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
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
hashsum
asked Aug 3 '15 at 22:41
tarabytetarabyte
1,00251832
1,00251832
1
If you need it to, then you canzip
it.
– ctrl-alt-delor
Aug 3 '15 at 22:48
add a comment |
1
If you need it to, then you canzip
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
add a comment |
2 Answers
2
active
oldest
votes
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.
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
add a comment |
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
1
But note that if you blindly compare the outputs ofshasum
, they will not match since the output includes the filename/path (as shown in your example). A good workaround is to do something likeshasum - < testfile
.
– DoxyLover
Aug 3 '15 at 22:53
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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
1
But note that if you blindly compare the outputs ofshasum
, they will not match since the output includes the filename/path (as shown in your example). A good workaround is to do something likeshasum - < testfile
.
– DoxyLover
Aug 3 '15 at 22:53
add a comment |
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
1
But note that if you blindly compare the outputs ofshasum
, they will not match since the output includes the filename/path (as shown in your example). A good workaround is to do something likeshasum - < testfile
.
– DoxyLover
Aug 3 '15 at 22:53
add a comment |
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
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
answered Aug 3 '15 at 22:42
tarabytetarabyte
1,00251832
1,00251832
1
But note that if you blindly compare the outputs ofshasum
, they will not match since the output includes the filename/path (as shown in your example). A good workaround is to do something likeshasum - < testfile
.
– DoxyLover
Aug 3 '15 at 22:53
add a comment |
1
But note that if you blindly compare the outputs ofshasum
, they will not match since the output includes the filename/path (as shown in your example). A good workaround is to do something likeshasum - < 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
If you need it to, then you can
zip
it.– ctrl-alt-delor
Aug 3 '15 at 22:48