Copy folder using find mkdir and copy
I have complex folder structure and only want to copy a subfolder and its contents that I have been working on to a new directory
for example: /data/group1/nmr/exp1/20/pdata/1.. /data/group1/nmr/exp1/20/pdata/10.. /data/group1/nmr/exp1/40/pdata/1.. /data/group1/nmr/exp1/40/pdata/10.. I want to copy /data/group1/exp1/40/pdata/10.. to /data/group2/exp1/40/pdata/10.. I have up to a hundred exp# with the same subfolders and only want to target the pattern ..40/pdata/10 so I #cd /data/group1/nmr/ #find -path ./*/40/pdata/10 -type d -exec cp "{}" /data/group2/nmr/"{}" \; but this wont work because destination looks like this: /data/group2/nmr/.exp1/40/pdata/10 So How do I copy contents of folder 10 (keeping the parent architecture that 10 is in to a new parent directory (group2)? In other words I need to remove the "." of my destination I have had success with making the directory architecture without files in the folders: #find . -type d -name "10" -exec mkdir -p -- /group1/nmr/"{}" \; AND I have found success in copying a subfolder 1 to a new folder 10 in the same directory by: #find -path .*/40/pdata -type d -exec cp "{}/1" "{}/10" \; |
Why not just use "cp -r src dest"?
|
because then I would have to delete all sufolders with .../20/pdata/1.. ../20/pdata/10 ..40/pdata/1..
and the list goes on ../999/pata/* and .../998/pdata/* so forth So I just want to focus on copying my experiments that have the subfolders...40/pdata/10/* and copy only that keeping the architecture otherwise the programme I use wont find my files - it uses this very specific architecture |
Quote:
|
[deleted a long and unnecessary digression on rsync]
|
Quote:
Code:
cp -vr --parents exp*/40/pdata/10 ../../group2/nmr/ |
Perfect Thanks berryloss I tried that and it worked... I began playing around with cpio (got various complaints about chmod permissions but still worked)
find -path .*/40/pdata/10/* -type f | cpio -pdv /data/group2/nmr |
A more general technique is start by building an array with the directory names you want to work on. Then you can loop over them to modify the names, copy subfiles, or whatever.
|
All times are GMT -5. The time now is 11:55 AM. |