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

Re: Rename files



ob6@inf.tu-dresden.de (Oswald Buddenhagen) wrote:
>> I'm trying to rename a lot of files. I just want to substitute underlines
>> with whitespaces. How can I do that?
>> 
>possibly not the easiest way, but it works:
>
>    for i in *; do mv "$i" "${i//_/ }"; done
>
>works only with bash 2.x (probably you have one ...).

If you don't have bash 2.x, try:

  for i in *; do mv "$i" `echo "$i" | tr _ ' '`; done

(note the various quotes there).

>you also could try mmv, but i don't know, if it is capable of this kind of
>operations.

Not in this case, no, though in general it's a really useful tool.

It's usually a bad idea to put spaces in filenames, though (or other
special characters like * and '). While they can normally be made to
work, I usually find that they only cause me problems later on. For
instance, you start having to use 'find -print0 | xargs -0' instead of
the more convenient forms.

-- 
Colin Watson                                           [cjw44@cam.ac.uk]


Reply to: