Reputation: 19395
I have many files in mypath that look like file_01.gz
, file_02.gz
, etc
I would like to compute the md5 checksums
for each of them, and store the output in a text file with something like
filename md5
file01 fjiroeghreio
Is that possible on linux?
Many thanks!
Upvotes: 0
Views: 217
Reputation: 7818
Linux already has a tool called md5sum, so all you need to do is call it for every file you want. In the approach below you get the default format of the md5sum tool, "SUM NAME", one per line for each file found. By using the double redirect (>>) each call will append to the bottom of the output file, sums.txt
#!/bin/bash
for f in *.gz; do
md5sum "$f" >> sums.txt
done
The above is illustrative only, you should probably check for the pre-existence of the output file, deal with errors etc.
There's lots of ways of doing this, so it all depends on further requirements. Must the format be of the form you state, must it recurse directories etc.?
Upvotes: 1
Reputation: 21502
You can use the shell filename expansion:
md5sum *.gz > file
Upvotes: 1
Reputation: 539
md5sum file*.gz > output.txt
Output file is space separated, without header
Upvotes: 2