Archive for July, 2008

Jul
12
Filed Under (Linux, LAMP) by Ernest Luk on 12-07-2008

This script is useful when dealing with a large volume of filename extensions. This script renames all files in a directory and its subdirectories with an ‘extension’ of sorts with the description of the file type. Other search techniques and batch renamers can then look after restoring these to common three letter extensions.

ren.sh

t="/tmp/ren"
find -type f > "$t"
while read record[n]
do
mv "${record[n]}" "${record[n]}.$(file -b "${record[n]}")"
let "n+=1"
done < "$t"
rm "$t"

then, for example, to correctly name all JPG files run (the complete list of files is too large to embed every option), where "JPG" begins the description and "jpg" is the new extension:

find -name "*.JPG" -print0 | xargs -0 rename .JPG .jpg