I don’t remember if I posted this little snippet of shell code, so I’ll risk it for the dup.
If you got yourself a messy directory with files – say, all filenames have a mixed case – you can put order in it pretty easy. The example below lowercases filenames of all Jpeg files (JPG and JPEG extensions) in the current directory.
for FILE in *.JP*G do mv "$FILE" `echo "$FILE" | tr A-Z a-z` done
The algorithm is very simple. For each file in the current directory that has an extension of JPEG or JPG (actually with any symbol between JP and G) execute a mv
command. mv
requires two arguments – the source filename and the destination. For the source argument we provide it with the name of the currently processed file. The destination filename we find out by filtering the name of the currently processed file through the tr A-Z a-z
command.
What does the tr A-Z a-z
command do? It simply substitutes latters in one range from appropriate letters in another range. The first range in this example includes all uppercase letters (A-Z), while the second range includes all lowercase letters (a-z).
That’s all folks…