Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Script to convert filenames to lowercase depending on extension

share|improve this question
add comment

2 Answers

To do it recursively for a number of extensions, you could use zsh's zmv:

zsh -c '
   autoload zmv
   ext=(jpg mp3 ogg)
   zmv -n "(**/)(*.(#i)(${(j:|:)ext}))" "\$1\${(L)2}"'

(remove -n (or replace it with -v) when happy).

Above the (#i) is to turn on case insensitive globbing, and ${(j:|:)ext} is to join the elements of the $ext list with |. You could also directly write it:

zsh -c '
   autoload zmv
   zmv -n "(**/)(*.(#i)(ogg|jpg|mp3))" "\$1\${(L)2}"'
share|improve this answer
    
Hi Stephane Chazelas Thanks a lot. –  gfhfghfg Dec 21 '12 at 7:08
    
is zsh is more powerful than bash ? i see your code seems regex like syntax, but didn't understand , do you have any link for zsh noob ? i want to learn. thanks in advance . i will delete this comment after 6 hrs. –  Rahul Patil Dec 26 '12 at 6:21
    
stephane i dnt know zsh could u pls help me in bash scripting.... –  gfhfghfg Dec 26 '12 at 11:11
add comment

I'm not sure how your question links to the code, so I'll focus on the question.

In bash versions 4 and above, you can do this by using something like the following:

for file in ./*.JPG; do     # Iterate over all items in the current directory that match *.JPG
    mv "$file" "${file,,}"  # Move the file found to a lowercase mapping (this is what the ,, parameter expansion method does)
done

Obviously replace *.JPG with the equivalent extension you're wanting.

share|improve this answer
    
I am using 3.2.25(1)-release –  gfhfghfg Dec 21 '12 at 7:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.