outputshchecksumbasename

Removing full path from md5 output


By default the md5 command includes the full path in the output and doesn't seem to have an option to output the basename only. Although I can get around this using a script, I wondered if there is a simple way to output without the full path using a single command. It doesn't have to be md5 as my aim is just to verify there is no corruption in files stored on different machines in my own network. As I am doing a simple diff on list of files with different paths, I just need to avoid the path muddying the waters.

At the moment I am using

find -s directoryToBeChecked -type f -exec md5 {} \; > checksumsForComparison.txt

to create pairs of files and would like to manually check them using a graphical diff program like FileMerge.

I'm using MacOS 10.14 so the shell is sh 3.2


Solution

  • Try to open a shell with a command argument echoing the basename and md5 (with the -q flag thus only printing the hash).

    find -s directoryToBeChecked -type f -exec sh -c 'echo "$(basename "$0") $(md5 -q "$0")"' {} \; > checksumsForComparison.txt