LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-20-2004, 06:44 AM   #1
jan_81
LQ Newbie
 
Registered: Sep 2003
Location: Milan
Distribution: RedHat
Posts: 9

Rep: Reputation: 0
Script to change several filename


I need to change many filename that have similar name.
Example:

I have about 100 file named "hello world" and I want change all them name in "hi world".
I've tried some command like "find" and "mv" but I didn't manage to make it...

Thanks.. by the way Hi all!!

Jan
 
Old 04-20-2004, 08:11 AM   #2
TroelsSmit
Member
 
Registered: Feb 2004
Location: Denmark
Distribution: Debian / Suse
Posts: 223

Rep: Reputation: 30
Put an if sentence and a concatenation into the following script:

#!/usr/bin/tcsh
#filer i et directory
foreach fil (`find /home/you/path -type f`)
mv $fil $newfilname
end
 
Old 04-20-2004, 08:45 AM   #3
jan_81
LQ Newbie
 
Registered: Sep 2003
Location: Milan
Distribution: RedHat
Posts: 9

Original Poster
Rep: Reputation: 0
Perhaps I didn't explain very well.. sorry for my bad english..

I have several similar files...

00001-hello-world-00001
00002-hello-world-00002
00003-hello-world-00003
...
...

I want to change for all these files the word "hello" with the word "hi" so that I'll have the files named

00001-hi-world-00001
00002-hi-world-00002
...
 
Old 04-22-2004, 09:06 AM   #4
jan_81
LQ Newbie
 
Registered: Sep 2003
Location: Milan
Distribution: RedHat
Posts: 9

Original Poster
Rep: Reputation: 0
up
 
Old 04-24-2004, 03:22 AM   #5
Muzzy
Member
 
Registered: Mar 2004
Location: Denmark
Distribution: Gentoo, Slackware
Posts: 333

Rep: Reputation: 30
This seems to work, although its not clear form your description if all the files are in the ssame directory or in different directories. If they are in different directories then this won't work without some modification.

for f in *; do mv "$f" "`echo $f | sed s/hello-world/hi-world/`"; done

Be careful with all the " and ` s!!

There is probably a better way of doing this, and I would like to see other people's improved suggestions, but this should do for your purposes.

Mark.

Last edited by Muzzy; 04-24-2004 at 03:25 AM.
 
Old 04-28-2004, 12:10 PM   #6
jan_81
LQ Newbie
 
Registered: Sep 2003
Location: Milan
Distribution: RedHat
Posts: 9

Original Poster
Rep: Reputation: 0
I don't mind the better way, it's important that it works..
Anyway, for the moment I can't try your script. I've just resolved the problem in another way... manually one by one!! Surely I'll try your script the next time and I'll make you to know as it goes...

Thanks

Bye at 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
change uploaded files from filename.avi to filename.avi.html like www.rapidshare.de latheesan Linux - Newbie 3 06-16-2005 05:33 AM
How to change a mass of filename in a dir? superztnt Linux - General 4 07-27-2004 08:29 AM
Bash script to change a filename associated with an inode index number. Ziv Programming 22 06-19-2004 09:41 AM
Can't change filename with SMB share InEeDhElPlInUx Linux - Security 0 04-01-2004 08:08 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-06-2003 12:58 AM


All times are GMT -5. The time now is 12:21 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration