Thursday, July 26, 2012

Bash for-loop renaming special characters from a list of files

This shows how AWESOME bash is

i=1; for f in ./*.doc; do printf -v num %05d $((i++)); mv "$f" $num.doc; done

A for-loop that iterates all files ending with .doc in the current dir. It uses the printf command to generate a five-digit, zero-padded, incrementing number, then uses the mv command to rename from old name to XXXXX.doc, where XXXXX is the 5-digit number.


No comments:

Post a Comment