batch rename
Michel Talon
talon at lpthe.jussieu.fr
Sat Jan 5 03:13:01 PST 2008
Aryeh M. Friedman wrote:
> My goal is to rename several files in such a way as to decapitalize
> > starting letters in their names. The solution seems to be simple
> > but I'm stuck. What should I use? awk/sed or write some
> > shell-script?
>
> This assumes tcsh:
>
> foreach i (`ls [A-Z][a-z]*`)
> mv $i `echo $i|tr 'A-Z' 'a-z'`
> end
This will disfunction if the names have embedded white spaces. I happen
to batch rename songs etc. which almost invariably have white spaces and
other horrors. So i use something like
mv "$i" `echo $i|sed -e 's/ */_/g' -e '.....' `
Sed has the advantage you can do several transformations at one stroke,
and fine tune the transformations. Double quotes avoid that the shell
breaks names on white space.
--
Michel TALON
More information about the freebsd-questions
mailing list