LinuxQuestions.org
Visit Jeremy's Blog.
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 07-20-2011, 09:36 AM   #1
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Rep: Reputation: 16
rename several files


Hi,

I would like to rename several files using the 'rename' commands. Below, are the files that I would like to rename from

Code:
af_1.txt
honeyf_1.txt
gof_1.txt
to

Code:
amqf_1.txt
honeymqf_1.txt
gomqf_1.txt

How can I do that using the 'rename' command?
 
Old 07-20-2011, 09:44 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
If you type
Code:
man rename
then it tells you:

Quote:
NAME
rename - Rename files

SYNOPSIS
rename from to file...
rename -V

DESCRIPTION
rename will rename the specified files by replacing the first occurrence of from in their name by to.
So, assuming I've interpreted you correctly as wanting to replace the "f_1.txt" with "mqf_1.txt", then you can use:

Code:
rename f_1.txt mqf_1.txt *
 
Old 07-20-2011, 09:51 AM   #3
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Original Poster
Rep: Reputation: 16
Thanks Snark1994, but I want to rename from af_1.txt to amqf_1.txt, or from honeyf_1.txt to honeymqf_1.txt, and not like you posted.

This is what I did, and it doesn't work:

Code:
~/a$ rename -v -n 's/*f_1.txt/*mqf_1.txt/' *.txt                                                                                               
Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HERE f_1.txt/ at (eval 1) line 1.
 
Old 07-20-2011, 09:56 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Code:
rename -v -n 's/f_1.txt/mqf_1.txt/' *.txt
The * in regular expressions has a special meaning (0 or more occurrences of the previous character) which is different from the globbing * used in patterns. The above should work (if you have the PERL version of the rename command). That one suggested by Snark1994 works for the util-linux version of rename (usually installed on RedHat-like systems).
 
Old 07-20-2011, 10:02 AM   #5
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Original Poster
Rep: Reputation: 16
It worked.

Thanks all.
 
  


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
Application to eliminate doubles in files and rename changed files with date? S. Chapelin Linux - Software 6 01-16-2011 03:02 AM
[SOLVED] How to rename files drnick911@yahoo.com Linux - Newbie 6 10-21-2010 05:23 PM
Trouble with making a bash script to read in different files and rename output files. rystke Linux - Software 1 05-07-2009 09:00 AM
how to rename files bkcreddy17 Programming 7 09-14-2008 10:22 AM
rename files linux2man Linux - General 8 02-03-2007 06:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:02 PM.

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