md5sum only new files?

3

1

I have a directory containing files and an md5sum.txt file. I add a file new files to the directory. I would like add md5sum sums for all files that are not in md5sum.txt.

Is there a simple way to do it?

user13798

Posted 2009-11-04T21:32:22.980

Reputation: 361

1What kind of script are you looking for? What operating system are you using? – innaM – 2009-11-04T21:35:59.430

you basically have to script reading in your md5sum.txt and directory listing and weed out from there. i'd probably choose perl for the task. – quack quixote – 2009-11-04T21:49:11.777

I'm using Linux. – user13798 – 2009-12-02T20:23:42.383

Answers

2

You can try this little number:

#We want the seperator to be newlines, not spaces
IFS="$(echo -e "\n\r")"
for EACHFILE in `ls -1`
do
    # If grep can't find the filename in that text file
    if ! egrep -q  " $EACHFILE$" md5sum.txt; then
    md5sum $EACHFILE
    fi
done

This assumes that the text file is like this:

964e6b94e921b5f0879b41956b787050 test.file

Which is standard output

Kyle-tummy.com

Posted 2009-11-04T21:32:22.980

Reputation: 342

In OSX I had to change the second line to: IFS=$'\n' – Josep Valls – 2015-09-14T16:47:58.817