LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   rename command does not work! (https://www.linuxquestions.org/questions/linux-general-1/rename-command-does-not-work-514000/)

wtn2die 12-27-2006 06:23 AM

rename command does not work!
 
Hello!

I'm trying to rename some files with spaces with the 'rename' command and a perl regexp:

Code:

rename 's/ //g' *
but it does not work!

I also tried:

Code:

rename ' ' '' *
But it does not working...

I solved the problem with a bash script, but i like this bad documented command. :)

What's wrong with it? :(

Thanks :)

--
Vinícius André Massuchetto

colucix 12-27-2006 06:33 AM

You should escape the blank-space. Try

Code:

rename \  "" *
Please, note the double space after \

wtn2die 12-27-2006 07:58 AM

I also tried this.

and also things like:

Code:

rename 's/\ //g'*
:(

colucix 12-27-2006 08:09 AM

The regexp version does not work for me, too... but the escaped space yes! Can you post the name of the files you are trying to rename? Sorry for the pedantic question, but are you sure to have put another space after the escaped one?

Code:

rename \  "" *

wtn2die 12-27-2006 08:23 AM

No problem, here it is...

Code:

-bash-3.00$ ls
Amor Real - Natal 003.jpg*  Amor Real - Natal 037.jpg*
Amor Real - Natal 004.jpg*  Amor Real - Natal 038.jpg*
Amor Real - Natal 005.jpg*  Amor Real - Natal 041.jpg*
Amor Real - Natal 006.jpg*  Amor Real - Natal 042.jpg*
Amor Real - Natal 007.jpg*  Amor Real - Natal 044.jpg*
Amor Real - Natal 009.jpg*  Amor Real - Natal 045.jpg*
Amor Real - Natal 010.jpg*  Amor Real - Natal 046.jpg*
Amor Real - Natal 011.jpg*  Amor Real - Natal 047.jpg*
Amor Real - Natal 012.jpg*  Amor Real - Natal 049.jpg*
Amor Real - Natal 013.jpg*  Amor Real - Natal 050.jpg*
Amor Real - Natal 014.jpg*  Amor Real - Natal 051.jpg*
Amor Real - Natal 016.jpg*  Amor Real - Natal 052.jpg*
Amor Real - Natal 017.jpg*  Amor Real - Natal 055.jpg*
Amor Real - Natal 018.jpg*  Amor_Real_-_Natal_056.avi*
Amor Real - Natal 019.jpg*  PC210054.JPG*
Amor Real - Natal 021.jpg*  PC210055.JPG*
Amor Real - Natal 024.jpg*  PC220056.JPG*
Amor Real - Natal 029.jpg*  PC220061.JPG*
Amor Real - Natal 030.jpg*  PC220091.JPG*
Amor Real - Natal 031.jpg*  PC220092.JPG*
Amor Real - Natal 033.jpg*  PC220094.JPG*
Amor Real - Natal 034.jpg*  Thumbs.db*
Amor Real - Natal 036.jpg*

And there's only one space: the escaped one.

makyo 12-27-2006 10:07 AM

Hi.

I wrote a little script to re-create some of the jpg filenames that you posted.

Then, either in a script or as a plain command:
Code:

rename 's/ //g' *.jpg
worked for me -- all the spaces in the filenames were removed.

Something else might be wrong here. Were you in the directory containing the files? Are you sure that the spaces are spaces? Can you rename any file in that directory? ... cheers, makyo

( edit 1: typo )

wtn2die 12-27-2006 11:00 AM

My problem is not to rename the files, but why
Code:

rename 's/ //g' *.jpg
does not work. :(

I always used this command, but in this Mandriva Linux 2006 is not working.

For renaming, scripts like
Code:

for f in *; do
    file=$(echo $f | tr A-Z a-z | tr ' ' _)
    [ ! -f $file ] && mv "$f" $file
done

do the job.

Is there a perl lib I must have to run them?
Yes, I can normally rename files in the folder.


All times are GMT -5. The time now is 07:14 AM.