I want to copy some files and include their parent directory in the process.The current structure is similar to:/Module1/A/downloads/m13312/file.pdf/Module1/A/downloads/m17312/file.pdf/Module1/B/downloads/m18312/file.pdf/Module2/A/downloads/m19312/file.pdfI want to grab the final two sections of the path so that I end up with:/mydir/m13312/file.pdf/mydir/m17312/file.pdf/mydir/m18312/file.pdf/mydir/m19312/file.pdfI've tried to use cut and awk to get the right results but I just cannot seem to get the path to return properly. Here's an example to just echo what I need (I haven't got to the copying part yet):find . -type 'f' -path '*downloads*' -print0 | xargs -0 -I {} echo `cut -d/ -f4-5 <<<{}`This just prints out the whole path so I know that I can't use this yet.
Copy files with parent folder to a new directory
awk;find;cp;xargs;cut
If your pax supports the -0 option:find . -type 'f' -path '*downloads*' -print0 |  pax -rw0s'|.*downloads/||' /mydir