Wednesday, December 2, 2015

Linux: Compare if two files are the same

Quick script I wrote in my .bashrc to check if two files are the same:

#md5sum
function md5comp()
{
    a=$(md5sum $1 | awk '{print $1}')
    b=$(md5sum $2 | awk '{print $1}')
    echo "Comparing $1 and $2"
    [ "$a" = "$b" ] && echo  "Equal" || echo "Not Equal"
}

Usage:
$ md5comp filea.txt fileb.txt
Comparing filea.txt and fileb.txt
Equal