Will changing a file name affect the MD5 Hash of a file?
In Linux using EXT filesystem, it will not, because a file name is not stored in a file, it is stored in the directory entry (dentry) that the file lives in, where the inode of the file is then mapped to a name. Changing a filename will have no affect on its md5sum in Linux. In Windows, I cannot be sure.
The usual definition of "MD5 hash of a file" is that the hash is based on the file contents. The name can be freely changed.
$hash1 = md5(file);
// change file name
$hash2 = md5(file);
The two hash codes will be the same.
In some (fairly specialized) use cases, file metadata (name, time stamp(s), etc.) are part of the data used to compute the hash. Then
$hash1 = md5(file);
// change file name
$hash2 = md5(file);
will produce two separate hashes.
No, the hash is of the file contents only. You can see this in the source for md5sum
and its MD5 implementation. You can also test this if you have access to md5sum
:
$ echo "some arbitrary content" > file1
$ cp file1 file2
$ md5sum file1
f0007cbddd79de02179de7de12bec4e6 file1
$ md5sum file2
f0007cbddd79de02179de7de12bec4e6 file2
$