Using md5deep
md5deep -r path/to/dir > sums.md5
Using find and md5sum
find relative/path/to/dir -type f -exec md5sum {} + > sums.md5
Keep in mind that when you start checking your MD5 amounts using md5sum -c sums.md5 you need to run it from the same directory from which you created the sums.md5 file. This is because find displays paths related to your current location, which are then placed in the sums.md5 file.
If this is a problem, you can make the absolute value relative/path/to/dir (e.g. by putting $PWD/ in front of your path). Thus, you can run the sums.md5 check from anywhere. The downside is that sums.md5 now contains absolute paths, which makes it bigger.
Full featured using find and md5sum
You can put this function in your .bashrc file (located in the $HOME directory):
function md5sums { if [ "$#" -lt 1 ]; then echo -e "At least one parameter is expected\n" \ "Usage: md5sums [OPTIONS] dir" else local OUTPUT="checksums.md5" local CHECK=false local MD5SUM_OPTIONS="" while [[ $# > 1 ]]; do local key="$1" case $key in -c|--check) CHECK=true ;; -o|--output) OUTPUT=$2 shift ;; *) MD5SUM_OPTIONS="$MD5SUM_OPTIONS $1" ;; esac shift done local DIR=$1 if [ -d "$DIR" ]; then
After running source ~/.bashrc you can use md5sums as a regular command:
md5sums path/to/dir
will generate checksums.md5 file in the path/to/dir directory containing the MD5 sum of all the files in this directory and subdirectories. Using:
md5sums -c path/to/dir
to check the amounts from the path/to/dir/checksums.md5 file.
Note that path/to/dir can be relative or absolute, md5sums will work anyway. The resulting checksums.md5 file always contains paths relative to path/to/dir . You can use a different file name, and then defaults to checksums.md5 by specifying the -o or --output option. All parameters except -c , --check , -o and --output are passed to md5sum .
The first part of the md5sums function md5sums is responsible for parsing parameters. See this answer for more details. The second half contains explanatory comments.
Tewu
source share