Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving Files between directories 1

Status
Not open for further replies.

yvsatyaprasad

Programmer
Aug 10, 2004
4
US
Hi-
I have two directories called temp and temparchive.Both the directories have got subdirectories(with same names) with files in them.I need to copy the subdirectories(with the files in them) from temp to tempArchive and then delete the files that are present in the subdirectories with in the temp directory.
Thanks in Advance
 
man tar

(cd path2temp && tar cf - . ) | (cd path2tempArchive && tar xvfp -)

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
vlad-
I don't want to do a tar on it,i already have tar files in my temp directory.
 
If you don't like tar then man cpio.
BTW have you really read vlad's post ? No tar file will be created...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I don't think you understand vgersh99's reply. He's not creating tar files. He's just using [tt]tar[/tt] to copy the whole directory tree over to the destination directory.

Try it, you'll like it.
 
How about this for an idea. Move the files from their location in temp to the equivalent location in tempArchive, then deleting won't be necessary. eg:
for file in `find /path-to/temp`
do
newfile=`echo "$file" | sed "s?/path-to/temp?/path-to/tempArchive?"`
mv $file $newfile
done

I hope that helps you.

Mike
 
Hi,
Just had a quick thought. I posted the above without testing it. The code will move the directories as well as any files in them. If only the files are to be moved then use:

for file in `find /path-to/temp -type f`
do
. . .
done

I hope that helps.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top