I want to verify integrity of folder. The folder has so many files and folders. How to calculate hash value of directory as a whole on Ubuntu. md5sum calculate at only file level.
Asked
Active
Viewed 1.3k times
4 Answers
5
For a list of md5sums:
find /path/to/dir/ -type f -exec md5sum {} \;
And for an overall md5 checksum:
find /path/to/dir/ -type f -exec md5sum {} \; | md5sum
Example output:
b2d5d3a5e102aae48eb6ff36c602ac75 -
Notice, at a folder with huge size, it can take very long.
chaos
- 27,106
- 12
- 74
- 77
-
1Notice md5sum prints the filenames alongside md5 hashes. So the path of both directories must be the same for an overall md5 checksum. So change the current directory to the one you want the md5 checksum for that and use `find . -type f -exec md5sum {} \; | md5sum` or delete filenames before using md5sum by `find /path/to/dir/ -type f -exec md5sum {} \; | awk '{ print $1 }' | md5sum`. – Dante Jan 11 '17 at 04:24
3
Install md5deep with
sudo apt-get install md5deep
The command
md5deep -r {direcotory}
you will get a hash based on all the files in the directory. You can also use md5deep to compare hashes of the files in the dir.
Rinzwind
- 293,910
- 41
- 570
- 710
-
1I am using 16.04. After `sudo apt-get install md5deep` done, I get `md5deep: command not found`! – Dante Jan 11 '17 at 04:29
-
2In Ubuntu 16.04 md5deep is «**transitional dummy package for hashdeep**». So you must use: `hashdeep -r {directory}`. (Try first `hashdeep -h` to see all options.) – user68186 Jan 22 '18 at 19:18
-
1
I created dir-fingerprint that can be used to solve that. It creates fingerprint/hash for all the files in directory tree and saves it in a file, also telling you if the fingerprint has changed.
It can be installed with:
$ brew install nejckorasa/tap/dir-fingerprint
and used as:
$ dir-fingerprint <path_to_directory>
with output:
Old [8a7b73f9671004edd50500bc7d3f1837d841a5c086011207259eb2d183823adf]
New [8a7b73f9671004edd50500bc7d3f1837d841a5c086011207259eb2d183823adf]
@ <path_to_directory>/.fingerprint
Diff false
and .fingerprint file created
nejckorasa
- 111
- 3
0
I published a Python 3 package for that. Quick usage:
$ pip install git+https://github.com/sorgloomer/pyfstools.git@main
...
$ python -m pyfstools hash .
dir 0348bd69ad78babf85960500f5482cfc6f52d7215c5b094c20bed33a17628033
Works on Linux, Windows, works with S3 or GCS storage. See more at pyfstools .
Tamas Hegedus
- 210
- 2
- 5