Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print md5sum of results of a find command in Linux

Tags:

linux

find

md5sum

I am tryng to do checksum on all .jar files I can find in directory and its sub directories. Then print the filename with the checksum value to a file.

this is what I have.

md5sum | find -name *.jar >result.txt

I am trying to join two commands together that I know work individually.

Any help appreciated.

like image 348
James Mclaren Avatar asked Feb 08 '13 15:02

James Mclaren


People also ask

What is md5sum command used for in Linux?

On Unix-like operating systems, the md5sum command computes and checks an MD5 message digest, a string representing the cryptographic hash of data encrypted with the MD5 algorithm.

Is MD5 the same as md5sum?

The md5sum command is based on the MD5 algorithm and generates 128-bit message digests. The md5sum command enables you to verify the integrity of files downloaded over a network connection. You can also use the md5sum command to compare files and verify the integrity of files.


2 Answers

You could use something like this to execute a command on each file:

find . -name "*.jar" -exec md5sum {} \; >result
like image 81
iabdalkader Avatar answered Oct 05 '22 17:10

iabdalkader


This will also work to recursively hash all files in the current directory or sub-directories (thanks to my sysadmin!):

md5sum $(find . -name '*.jar') > result.txt

The above will prepend "./" to the filename (without including the path).

Using the -exec suggestion from mux prepends "*" to the filename (again, without the path).

The listed file order also differed between the two, but I am unqualified to say exactly why, since I'm a complete noob to bash scripting.

Edit: Forget the above regarding the prepend and full path, which was based on my experience running remotely on an HPC. I just ran my sysadmin's suggestion on my local Windows box using cygwin and got the full path, with "*./" prepended. I'll need to use some other fanciness to dump the inconsistent path and prepending, to make the comparison easier. In short, YMMV.

like image 28
kwolson Avatar answered Oct 05 '22 17:10

kwolson