1

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

yvf5rcuya4
  • 59
  • 6
  • Hmm, I don't know about MacOS... But you could try if `find -s directoryToBeChecked -type f -exec sh -c 'echo "$(basename "$0") $(md5 -q "$0")"' {} \; > checksumsForComparison.txt` works for you. – sticky bit Sep 26 '20 at 03:08
  • @stickybit Thanks for that. Your suggestion works and gives me exactly what I wanted. As you've just posted a comment rather than a reply I can't mark it as the solution. – yvf5rcuya4 Sep 26 '20 at 03:19
  • There you go, I've added an answer. – sticky bit Sep 26 '20 at 03:22

1 Answers1

1

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
sticky bit
  • 36,626
  • 12
  • 31
  • 42