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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to copy all the matched files with its original directories

Status
Not open for further replies.

sedawk

Programmer
Feb 5, 2002
247
US
Hi,


I am a new guy to AWK. I have a question which is an extension to my previous one about how to search files:

let's say we have 3 directories under /usr directory. Each of the 3 directories has *.pdf files that I need to search out. For example:
/usr/d1/f1.pdf
/usr/d1/f2.pdf
/usr/d1/d11/f3.pdf
/usr/d2/f4.pdf
...
/usr/d3/d31/d32/../x.pdf

the level of the directory is as more as 10 levels.

Now I used find command find out all *.pdf files, and I also want to do this:

create a new directory called "mypdf"(it could be also under /usr), under /mypdf I want copy those matched *.pdf files into /mypdf but in the maan time i want to keep the same directory structure as before, for example:
after the operation, i will have:
/usr/mypdf/d1/f1.pdf
/usr/mypdf/d1/f2.pdf
/usr/mypdf/d1/d11/f3.pdf
/usr/mypdf/d2/f4.pdf
etc. In other words, i want to maintain the original file structrue.

Since the original file structure is too big and too many matched files, I can't do that by hand.

Anyone can help me out?
 
sedawk:

You probably want to use the pass mode, -p, of cpio:

cd /usr/; find . -name "*.pdf" -depth -print|cpio
-pd /usr/mypdf

basically, cd to the directory you want to search. Tell find which files you want, and finally, pipe it to cpio. cpio handles creating any directories required.

Regards,


Ed
Schaefer
 
cd /usr/; find . -name "*.pdf" -depth -print|cpio
-pd /usr/mypdf

basically, cd to the directory you want to search. Tell find which files you want, and finally, pipe it to cpio. cpio handles creating any directories required.

Regards,


Ed
Schaefer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top