LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 11-05-2004, 06:20 PM   #1
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
Question Multiple file rename


I have about 50 files that I need to rename, and I don't want to do it manually. I looked into a few ways of doing this but I have spaces in the filenames which seems to complicate things. Can anyone let me know how to do this?

I want files named:

I\ Am\ A\ File\ -\ Sometexthere

renamed to:

Sometexthere

Thanks in advance.
 
Old 11-05-2004, 06:26 PM   #2
ror
Member
 
Registered: May 2004
Distribution: Ubuntu
Posts: 583

Rep: Reputation: 33
you'll need a script to do it, I was looking into this a while ago for windows, I got cygwin/bash just to do it, but it still needed to be scripted./

it used to be bookmarked

http://unix.about.com/library/glossa...p009.htm?zIr=5

but that link is dead now!

god damn about.com keep making their links die!
 
Old 11-05-2004, 06:30 PM   #3
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Original Poster
Rep: Reputation: 30
Can I do this sort of thing:

$ for f in filelist ... ; do mv "$f" "${f/oldname/newname}" ; done

even with the spaces (well, backslash escaped spaces) in there? I'd try but I'm afraid it's going to get confused by those and start renaming other things.
 
Old 11-05-2004, 06:42 PM   #4
tardigrade
Member
 
Registered: Jun 2004
Distribution: SuSE 9.1
Posts: 150

Rep: Reputation: 15
theres a nice program called krename thats good for that sort of thing. but i see you use slackware w/ fluxbox so thats probably no help to you. i posted for someone who may search into this fourm.
 
Old 11-05-2004, 07:48 PM   #5
ror
Member
 
Registered: May 2004
Distribution: Ubuntu
Posts: 583

Rep: Reputation: 33
firstly why do you think that would be no use?

Secondly it's probably nicer to do it from a shell anyway.

And yes, the script was along the lines of for X in ...
 
Old 11-06-2004, 12:32 AM   #6
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Original Poster
Rep: Reputation: 30
Slackware can use "k" programs, thank you very much . And thanks for the confirmation that that will work ror.

EDIT:
I just realized the command I typed doesn't do what I want it to do. Won't that just rename the entire file rather than changing part of it? What's the correct way to use a for statement to do what I want to do? Thanks.

Last edited by jrdioko; 11-06-2004 at 12:35 AM.
 
Old 11-06-2004, 12:36 AM   #7
ror
Member
 
Registered: May 2004
Distribution: Ubuntu
Posts: 583

Rep: Reputation: 33
use sed s/ to change the name.
 
Old 11-06-2004, 07:13 PM   #8
tardigrade
Member
 
Registered: Jun 2004
Distribution: SuSE 9.1
Posts: 150

Rep: Reputation: 15
next time ill just keep my mouth shut.
"firstly why do you think that would be no use?
Secondly it's probably nicer to do it from a shell anyway. "
my point exactly.
 
Old 11-06-2004, 07:41 PM   #9
ror
Member
 
Registered: May 2004
Distribution: Ubuntu
Posts: 583

Rep: Reputation: 33
heh sorry then, I thought you were one of the legions out there who are under the strange believe that kde apps have to be run under kde, etc (sadly a common belief around here ;( )
 
Old 11-07-2004, 04:14 PM   #10
LasseW
Member
 
Registered: Oct 2004
Distribution: Fedora 7, OpenSuse 10.2
Posts: 108

Rep: Reputation: 15
Assuming the part you want to remove is identical for all files, this should do the work:

for F in I*
do
mv "$F" ${F#I am file - }
done
 
Old 11-07-2004, 05:25 PM   #11
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Original Poster
Rep: Reputation: 30
Ok, I ended up doing it another way but I'll keep that in mind for next time. Thanks all for the suggestions.
 
  


Reply



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
Help with Bash Script - Rename Multiple Files embsupafly Programming 16 04-02-2010 03:50 AM
Multiple File Rename windisch Linux - General 11 11-10-2005 12:19 PM
How can i Rename file? Khmer Linux - Newbie 4 10-21-2005 08:09 AM
How do I rename a file? Thaidog Linux - Newbie 5 10-10-2003 10:28 PM
How to rename a file? juanb Linux - General 4 03-19-2003 11:20 AM

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

All times are GMT -5. The time now is 09:13 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
Open Source Consulting | Domain Registration