LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-29-2010, 02:43 PM   #1
Bringo
Member
 
Registered: Mar 2010
Posts: 31

Rep: Reputation: 16
Question doubt in rename command's syntax


Hi linux users,

I have many files in directory with names in this pattern:
foo-1.ext, foo-32.ext, foo-12.ext ...
I want to rename all these files as:
bar-1.ext, bar-32.ext, bar-12.ext ...

After reading man for rename, I am trying this way:

rename foo-*.ext bar-*.ext
and
rename foo-?.ext foo-??.ext bar-?.ext bar-??.ext

Both of my tries give no syntax error(s). But the files are also never renamed as desired. Please help me.
 
Old 04-29-2010, 03:08 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
The syntax for rename is:
Code:
rename from to filename
Example:
Code:
rename book movie *
This would find every file in the current directory with "book" in the name, and replace it with "movie"

I just tried this:
Code:
rename cm* CM *
This deleted one of two files containing cm in the name, and failed to rename the other!! This suggests that wild cards in the "from" field is not what you want to do. (Maybe some quoting would solve it??)
 
Old 04-29-2010, 03:11 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Another test suggests that you simply cannot have a wildcard in the "from" field
 
Old 04-29-2010, 03:24 PM   #4
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287
Quote:
Originally Posted by Bringo View Post
Hi linux users,

I have many files in directory with names in this pattern:
foo-1.ext, foo-32.ext, foo-12.ext ...
I want to rename all these files as:
bar-1.ext, bar-32.ext, bar-12.ext ...

After reading man for rename, I am trying this way:

rename foo-*.ext bar-*.ext
and
rename foo-?.ext foo-??.ext bar-?.ext bar-??.ext

Both of my tries give no syntax error(s). But the files are also never renamed as desired. Please help me.
just do:

Code:
rename foo bar *.ext
don't use wildcards in the other fields as they can cause problems.
 
Old 04-29-2010, 03:58 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
don't use wildcards in the other fields as they can cause problems.
AMEN!!!
 
Old 04-30-2010, 03:02 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by H_TeXMeX_H View Post
Code:
rename foo bar *.ext
Safer to quote the wildcarded string so it is not expanded by the shell and gets to rename as you intend
Code:
rename foo bar '*.ext'
 
Old 04-30-2010, 04:25 AM   #7
Bringo
Member
 
Registered: Mar 2010
Posts: 31

Original Poster
Rep: Reputation: 16
Thanks a lot to all of you,
Quote:
rename foo bar *.ext
worked.
 
Old 04-30-2010, 04:33 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by Bringo View Post
Thanks a lot to all of you,
worked.
Test it in a directory with files like A.ext, B.ext ...
 
Old 04-30-2010, 04:37 AM   #9
Bringo
Member
 
Registered: Mar 2010
Posts: 31

Original Poster
Rep: Reputation: 16
I tested it and it worked..
 
  


Reply


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CLI syntax for rename function? buccaneere Programming 11 10-19-2009 06:59 PM
[SOLVED] simple curl syntax doubt sl33p Linux - General 1 07-06-2009 04:18 PM
Interperting AT command's file names cmnorton Linux - General 1 04-28-2008 01:14 PM
suppress the command's result in script ramesh_manu Red Hat 2 02-16-2007 12:02 PM
Why several instances if command's only issued once? chadwick Linux - General 4 12-24-2005 08:25 PM


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

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration