* Micha Feigin ([EMAIL PROTECTED]) wrote:
> I am trying to do a batch rename for a bunch of files with spaces in the
> name (in order to remove the spaces actually). I tried to use bash's for
> .. in command but it splits up the lines on spaces and not on line ends.
> Any ideas?
> 
> The files are named "Copy of ..." and I want to drop the Copy of part.
> I tried to do
> for file in `ls -1`; do 
>   cp $file `echo -n "$file" | sed 's/Copy of \(.*\)/\1/'`
> done
> 
> but like I said the file name is split into three matches, one for
> "Copy", one for "of" and one for the rest (no more spaces).

perl installs a script called 'rename' which you can call like this:

rename -v 'y/\ /_/' * <== changes all spaces to underscores

rename -v 's/Copy\ of\ //' * <== replaces 'Copy of ' with nothing

the -v outputs a line telling you what each file has been renamed to.

if you've got lots of directories, try

find -name '*\ *' -exec rename -v 'y/\ /_/' \{\} \;

which i _think_ will work ok, but test it on non-critical files first.

iain

-- 
wh33, y1p33 3tc.

"If sharing a thing in no way diminishes it, it is not rightly owned if it is
not shared." -St. Augustine


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to