This blog allows me to disseminate knowledge I think should be readily available. If I find myself ranting, I try to make sure it's informative, and not completely subjective. I try to offer solutions--not problems--but in the case I do present a problem, please feel free to post a comment.
Sunday, March 18, 2007
Executing a command on multiple files with FIND
find ./ -regex ".*\.mp3" | tr \\n \\0 | xargs -0 -n 1 md5sum > mp3checksums.md5
But, you can also say:
find ./ -regex ".*\.mp3" -exec md5sum {} \; > mp3checksums.md5
Where, the {} implies to insert an individual argument into that part of the exec string, and the semicolon (escaped so it's not picked up by BASH) ends the -exec agrument.
Sunday, February 04, 2007
Shell Script to Parse Command Line Arguments
Solution: The following script.
#!/bin/bash
if [ ! -d Thumbs ] ; then
mkdir Thumbs;
fi
while [ $# -ge 1 ]; do
TARGET=`echo -n "$1" | sed "s/.jpg/t.png/" | sed "s/.JPG/T.PNG/" | sed "s/.jpeg/t.png/" | sed "s/.JPEG/T.PNG/"`;
if [ -e $TARGET ] ; then
echo "Refusing to overwrite $TARGET. ";
else
echo -n "Converting $1 to Thumbs/$TARGET: ";
convert $1 -resize 128x128 Thumbs/$TARGET;
if [ $? -eq 0 ]
then
echo "OK."
else
echo "ERROR: $?"
fi
fi
shift
done
exit 0
Monday, September 18, 2006
Create md5 sum files in Linux
Learned that the Linux shell can be quickly used to generate md5 checksums of an entire directory to an md5 file, the command is of the form:
cd [directory to generate check sums for]
find ./ -printf “%p\0” | xargs -0 -n 1 md5sum > ./checksums.md5
Then, to check the files in a new location (e.g. on a CD-ROM), use the command:
md5sum -c ./checksums.md5
Or there are other programs for validating the files with the checksums, like wxChecksums which is available for Windows.
I wanted this because the graphical wxChecksums was too difficult to compile, and didn't seem worth the effort. Although I'm sure a couple backwards-compatibility packages for gcc would fix this problem, the command-line method makes it straightforward for doing multiple check sums in a single command in text mode.