LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 01-14-2008, 01:07 AM   #1
SevenMedia
LQ Newbie
 
Registered: Jan 2008
Location: In My Mind
Distribution: CentOS 5
Posts: 3

Rep: Reputation: 0
Rename files and add prefix


Hello All,

New to the forum and new on linux,I want to ask about rename files,got some info when do search but not found what I looking for.

I want rename and add prefix on multiple files (morethan 4000 files).

I have file like this

mountain_small.jpg
mountain1_small.jpg
cars_big.jpg
animal_big.jpg

That I want result like this

mountain_small_oldpics.jpg
mountain1_small_oldpics.jpg
cars_big_oldpics.jpg
animal_big_oldpics.jpg

I search on the net and found command
rename 's/(\w{1})\.txt$/$1_thesis\.txt/' *.txt

and modify it like this

rename 's/(\w{1})\.jpg$/$1_oldpics\.jpg/' *.jpg

but not work.

Can anybody here help me to solve this problem.

Thanks in advance.
 
Old 01-14-2008, 01:45 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Welcome.
Use the search function whenever possible.
Also, if you have time, read up on shell scripting (see links in my signature).
 
Old 01-14-2008, 12:04 PM   #3
SevenMedia
LQ Newbie
 
Registered: Jan 2008
Location: In My Mind
Distribution: CentOS 5
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ghostdog74 View Post
Use the search function whenever possible.
Thanks for your reply.

Yes I know where must started before asking (myself owner forums with > 200k members).
I have use search function and found some solutions but as I mentioned I am newbie on linux and many of them must using script,I still dont understand,and thanks for the link,but still dont understand.

What I want someone here can give direct instruction with my example file above,if possible just copy and paste proceed.

If you dont want answer it for free,I can give you contribution back for php/mysql/xhtml/css help,I am expert on it.
 
Old 01-14-2008, 12:30 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Not sure what the problem on your system may be, the
invocation you quoted works flawlessly here. What
happens when you say "it doesn't work"? Are you getting
an error message, is it not doing anything?

The only (potential) issue I see is the extra $ in
the searchstring, it shouldn't be required; but it
does work w/ and w/o it here.
Code:
rename 's/(\w{1})\.jpg/$1_oldpics\.jpg/' *.jpg
as opposed to
Code:
rename 's/(\w{1})\.jpg$/$1_oldpics\.jpg/' *.jpg


Cheers,
Tink

Last edited by Tinkster; 01-14-2008 at 12:32 PM.
 
Old 01-14-2008, 01:27 PM   #5
SevenMedia
LQ Newbie
 
Registered: Jan 2008
Location: In My Mind
Distribution: CentOS 5
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks Tink,
When run your command and previous command no return any error message shown,after press enter ,just go back to prompt and files not renamed.
 
Old 01-14-2008, 03:23 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
How odd. Do they contain something silly like embedded leading spaces or something?
I really can't see why it wouldn't work.


Cheers,
Tink

Last edited by Tinkster; 01-14-2008 at 03:24 PM.
 
Old 01-16-2008, 08:04 AM   #7
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
Or any embedded spaces, for that matter.

Works fine here, too.

Note: this simple & potentially dangerous code, it has no safety checks * therefore must NOT be run 2ce on any directory -- it will produce file names like "cars_big_oldpics_oldpics.jpg".

I don't know if there is a simpler way, but the following filter prevents this:
Code:
ls *.jpg  | grep -v '_oldpics\.jpg'  | rename 's/(\w{1})\.jpg/$1_oldpics\.jpg/'
 
  


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
How can I change the prefix of multiple files in a directory 6millionbucks Programming 13 08-01-2007 12:05 PM
rename files linux2man Linux - General 8 02-03-2007 06:26 AM
how to rename muliple files manishsingh4u Linux - General 6 05-21-2006 08:59 AM
rename files allelopath Linux - General 5 07-05-2005 04:00 AM
Can not rename files. Maximus2000 Linux - General 0 04-22-2004 02:36 PM


All times are GMT -5. The time now is 08:36 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