Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Copying certain subdirectories retaining structure
On 02/22/2014 01:40 PM, Philippe Troin wrote:
On Sat, 2014-02-22 at 20:06 +0000, zzapper wrote:
I want to copy all files in subdirectories named /good/ to a USB while
retaining directory structure
/aaa/pic/good
/aan/dogs/good/
/dir1/dir2/dir3/good/
for i in **/good(/)
do
dest=/media/usbkey/$i
mkdir -p $i:h
cp -a $i /media/usbkey/$i
done
Phil.
This is less elegant but maybe more direct:
find . -name target -type d -exec cp --parents -r '{}' /aWorking/temp \;
.... where 'target' is the name of the dir you're looking for and in
this test case, I'm copying to /aWorking/temp/ from /aWorking/aJunk/
source tree:
pts/2 HP-y5-10-Debian1 root /aWorking/aJunk $ t
.
├── [ 12K] one
│ └── [8.0K] two
│ └── [4.0K] target
├── [ 20K] onea
│ └── [ 16K] twoa
│ └── [ 12K] threea
│ └── [8.0K] target
│ ├── [ 0] file1
│ ├── [ 0] file2
│ ├── [ 0] file3
│ └── [4.0K] subdir
│ ├── [ 0] file1
│ ├── [ 0] file2
│ └── [ 0] file3
└── [ 20K] oneb
├── [ 0] file1
├── [ 0] file2
├── [ 0] file3
└── [ 16K] twob
└── [ 12K] target
├── [ 0] file1
├── [ 0] file2
├── [ 0] file3
└── [8.0K] target
└── [4.0K] target
56K used in 13 directories, 12 files
target tree:
pts/2 HP-y5-10-Debian1 root /aWorking/temp $ t
.
├── [ 12K] one
│ └── [8.0K] two
│ └── [4.0K] target
├── [ 20K] onea
│ └── [ 16K] twoa
│ └── [ 12K] threea
│ └── [8.0K] target
│ ├── [ 0] file1
│ ├── [ 0] file2
│ ├── [ 0] file3
│ └── [4.0K] subdir
│ ├── [ 0] file1
│ ├── [ 0] file2
│ └── [ 0] file3
└── [ 20K] oneb
└── [ 16K] twob
└── [ 12K] target
├── [ 0] file1
├── [ 0] file2
├── [ 0] file3
└── [8.0K] target
└── [4.0K] target
56K used in 13 directories, 9 files
... correctly missing three files.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author