Index

Subject : LUG: How to copy full directory structure and only select files?

From : "Daniel Underwood" <daniel.underwood@ncsu.[redacted]>

Date : Thu, 05 Aug 2010 04:37:00 -0400


Suppose I have the following:

data
|-- 1
| |-- 0index.html
| |-- 0index2.html
| |-- 1.txt
| |-- 2.txt
| |-- 3.txt
| |-- 4.txt
| |-- 5.txt
| |-- 6.txt
| `-- file.dat
`-- 2
|-- 1.txt
|-- 2.txt
|-- 3.txt
|-- 4.txt
`-- file.dat

And I want to copy this entire directory (data/) to another location,
except for the fact that I only want to copy: (1) all directories and
(2) each "file.dat" file. So, the result copied to another location
should be the following:

data
|-- 1
| `-- file.dat
`-- 2
`-- file.dat

Without writing a script to walk the entire directory and check each
item before deciding whether to copy it to the destination directory,
how can I easily do this? Could I somehow recreate only the directory
structure and then find the file.dat's and pipe them to an xargs copy
command?

TIA guys...
--
Daniel Underwood
North Carolina State University
PhD Student - Industrial Engineering
email: daniel.underwood@ncsu.[redacted]
phone: XXX.302.3291
fax: XXX.515.5281
web: http://www4.ncsu.edu/~djunderw/



Replies :