I want to compare local folder and folder on server, folder can contain subfolders and subfolders can contain files.
How to compute md5sum for whole folder?
Update:
One possible solution will not to compute hash for whole folder, but to compute hash for each file and then compare lists of hashes.
Lets assume we want to compare folders a
and b
:
tree .
.
├── a
│ ├── 1.txt
│ └── d
│ └── 2.txt
└── b
└── 1.txt
This can show the difference:
find a -type f | sort | xargs md5 -r | cut -f1 -d " " > a.txt
find b -type f | sort | xargs md5 -r | cut -f1 -d " " > b.txt
git diff --no-index a.txt b.txt
But how to check which file corresponds to hash that is missing from one of the folders?
If I
cd a
find . -type f | sort | xargs md5 -r > ../a.txt
cd ..
cd b
find . -type f | sort | xargs md5 -r > ../b.txt
cd ..
git diff --no-index a.txt b.txt
This solves a problem, however maybe not very elegant.
The solution with zip in other answer look good, but for me have some disadvantages, it need to zip the files, do not show which file is different.
Because of this I will offer one sample solution:
If you have subdirectories and files and want to include those files too use
transfer
tmp_file
to other server and execute there(if
tmp_file
is transferred in/tmp
directory) and you will see output like this:Using rhash to output md5 hashes to file.
Verify hash from files.
rhash options:
-M
MD5: calculate and print MD5 hash sum.-r
Recursively process directories, specified by command line.-o
Set the file to output calculated hashes and verification results.-c
Check hash files specified by command line.Saving directory structure to the same file.
Compare files line by line.