[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: file extensions -- batch mv'ing, mp3s



> 
> To change .MP3 to .mp3 in a given directory, I do this (anyone know an
> easier/more efficient way?):
> 
> $ for x in *;do mv -iv "$x" `echo "$x"|sed -e 's/MP3$/mp3/'`;done
>

I usually do something like this:

bash$ for i in *.MP3; do mv $i ${i%.MP3}.mp3; done

I don't know if ${var%pattern} is a bashism or not.

The ${var%pattern} returns the value of $var, with the shortest suffix 
matching the pattern (a filename glob) deleted.  Using %% instead of % 
removes the longest suffix, and # and ## remove the shortest and 
longest prefixes.

I think it's shorter, clearer, and more efficient.

Any better ways?

 
-- 
     Buddha Buck                      bmbuck@zaphid.dhis.edu
"Just as the strength of the Internet is chaos, so the strength of our
liberty depends upon the chaos and cacaphony of the unfettered speech
the First Amendment protects."  -- A.L.A. v. U.S. Dept. of Justice



Reply to: