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-06-2005, 10:31 AM   #1
basher400
Member
 
Registered: Mar 2005
Posts: 54

Rep: Reputation: 15
shell question: the "mv" command with multiply files


hi

I have the following folder structure:

folder1
subfolder1.1
subfolder1.2
subfolder1.3

folder2
subfolder2.1
subfolder2.2
subfolder2.3

where is "subfolder1.1" is a subfolder under "folder1"
I have 2 files in each subfolder: "index.html", and "index_new.html"

I would like to rename "index_new.html" to "index.html", and by doing so to overwrite "index.html", and be left with only the "index.html" file (which content is what was in "index_new.html") in one command line.

this is basically what the "mv" command is used for.

why isn't this working for it:
mv folder[0-9]/subfolder*/index_new.html folder[0-9]/subfolder*/index.html

should I be using the "$0" var or am I completely off track with this?

Thanks
 
Old 04-06-2005, 11:22 AM   #2
jkobrien
Member
 
Registered: Jun 2003
Location: Dublin, Ireland
Distribution: Slackware, LFS, Ubuntu, RedHat, Slamd64
Posts: 507

Rep: Reputation: 30
If the mv command is given several arguments (filenames) the last one has to be a directory name. You are trying to move all the index__new.html files to one file.

Try 'find' or 'foreach'

John
 
Old 04-06-2005, 12:44 PM   #3
sirclif
Member
 
Registered: Sep 2004
Location: south texas
Distribution: fedora core 3,4; gentoo
Posts: 192

Rep: Reputation: 30
john is right. the reason is that one of the first things the shell does is expand the command line, so file[1-3] is expanded to file1 file2 file3, the mv command is then passed a long list of filenames. i actually have written a small script that allows you to do what your looking for. if you have a file containing all the old filenames, and onother containing all the new filenames, it will go down the list and move one to the other. i dont have time right now, but if you want i can post the script later.
 
Old 12-19-2005, 05:41 AM   #4
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Try the following:

dirs=`find folder1 folder2 -type d`;

$dirs now contains al list of all subfolders in folder1 and folder2 (note: also
subfolders of subfolders).
So, we must now try to issue a "mv" command for all subfolders in $dirs

In Bash, this is something like:

for i in $dirs; do
mv ${i}/index_new.html ${i}/index.html
done

In this case, it's easy to verify if your "mv" commands are correct before actually
executing them. You can accomplish this by enclosing the "mv" command in an "echo" command
like:
echo "mv ${i}/index_new.html ${i}/index.html"
and running that in the same loop as above.
If the "mv" commands that are printed to your screen seem OK to you, execute the loop
as it is written above (without the echo).

Or:

for i in $dirs; do
cd ${i}
mv index_new.html index.html
cd -;
done
 
Old 12-19-2005, 07:42 AM   #5
sirclif
Member
 
Registered: Sep 2004
Location: south texas
Distribution: fedora core 3,4; gentoo
Posts: 192

Rep: Reputation: 30
or this in the root directory

Code:
rename index_new index */*/*.html
...if this thread is still alive.
 
  


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
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
Reconfigure command in "perl -MCPAN -e shell" asciimonster Linux - Software 1 09-16-2004 08:48 AM
"make" command not working in shell unasriseth Linux - Newbie 6 05-25-2004 09:08 AM
equivalent of "what" shell command in Linux raees Linux - General 4 03-16-2004 08:59 AM
"how do I extract a number from a text file using shell command?" sdandeker Linux - Networking 3 02-12-2004 08:54 AM

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

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