i need bash /shell/ script to md5sum hash all current directory tree files to one single .csv file like this :
"index.php","add95c73ccafa79b4936cf7236a074f4"
"logs/index.html","1c7b413c3fa39d0fed40556d2658ac73"
Thank You very much ;)
i need bash /shell/ script to md5sum hash all current directory tree files to one single .csv file like this :
"index.php","add95c73ccafa79b4936cf7236a074f4"
"logs/index.html","1c7b413c3fa39d0fed40556d2658ac73"
Thank You very much ;)
You can try the command below, but it will only work if:
"
characters in your filenamesIf that's OK, then this should work for you:
find . -type f -print0 | xargs -0 md5sum | \
sed -r 's/^([0-9a-f]{32}) (.*)/"\2","\1"/'
Otherwise you'll need to do proper CSV quoting, in which case I'd suggest writing a short Python script to do this, using the csv module. For example:
#!/usr/bin/env python
import os, csv, sys, subprocess, hashlib
writer = csv.writer(sys.stdout, quoting=csv.QUOTE_ALL)
for directory, subdirectories, filenames in os.walk('.'):
for filename in filenames:
h = hashlib.md5()
full_filename = os.path.join(directory, filename)
with open(full_filename, 'rb') as f:
while True:
data = f.read(8096)
if len(data) == 0:
break
h.update(data)
writer.writerow([h.hexdigest(), full_filename])
Try:
find . -type f -print0 | xargs -0 md5sum | perl -pe 's/^(.*?)\s+(.*)$/"$2","$1"/'
> md5.csv
md5sum * | awk '{ print "\"" $2 "\",\"" $1 "\"" }'
This should work
perl -pne 's/^"(.*)","([0-9a-f]+)"$/$2 *$1/io' < input | md5sum -c
You can do it as shown below. Below, I am using the cksum utility which calculates the CRC checksum. You can use your utility which generates the MD5 checksum. You can redirect the output to a .csv file.
#!/bin/ksh
for file in $(find $1 -type f)
do
filename=$(basename $file)
checksum=$(cksum $file | cut -d " " -f 1)
echo \"${filename}\",\"${checksum}\"
done