LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 12-27-2006, 06:23 AM   #1
wtn2die
LQ Newbie
 
Registered: May 2006
Distribution: Debian
Posts: 13

Rep: Reputation: 0
Unhappy 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

Last edited by wtn2die; 12-27-2006 at 07:59 AM.
 
Old 12-27-2006, 06:33 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,503

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
You should escape the blank-space. Try

Code:
rename \  "" *
Please, note the double space after \
 
Old 12-27-2006, 07:58 AM   #3
wtn2die
LQ Newbie
 
Registered: May 2006
Distribution: Debian
Posts: 13

Original Poster
Rep: Reputation: 0
I also tried this.

and also things like:

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

Last edited by wtn2die; 12-27-2006 at 08:12 AM.
 
Old 12-27-2006, 08:09 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,503

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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 \  "" *
 
Old 12-27-2006, 08:23 AM   #5
wtn2die
LQ Newbie
 
Registered: May 2006
Distribution: Debian
Posts: 13

Original Poster
Rep: Reputation: 0
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.

Last edited by wtn2die; 12-27-2006 at 08:24 AM.
 
Old 12-27-2006, 10:07 AM   #6
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 718

Rep: Reputation: 72
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 )

Last edited by makyo; 12-31-2006 at 03:53 PM.
 
Old 12-27-2006, 11:00 AM   #7
wtn2die
LQ Newbie
 
Registered: May 2006
Distribution: Debian
Posts: 13

Original Poster
Rep: Reputation: 0
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.
 
  


Reply

Tags
rename, renamescript


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
the rename bash command is malfunctioning nicdee Linux - General 10 04-29-2006 09:02 AM
rename command or PERL perlexpr? malaka56 Linux - Software 1 08-24-2005 12:34 PM
rename reboot command coco03 Linux - General 6 04-19-2005 02:11 AM
rename command won't work Red Squirrel Linux - Newbie 4 03-03-2004 08:53 PM
rename with command line shanenin Linux - Software 1 09-25-2003 07:03 PM


All times are GMT -5. The time now is 11:22 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration