I have a lot of different folders with pdf
files and other extensions. I want to copy all the pdf
files to another destination. But if I do that with find like this:
"${SEARCHDIR}" -iname "*.pdf" | xargs -d "\n" -I {} cp -r --backup=t {} "${OUTPUTFOLDER}/"
I get all the pdf
files in single destination and that is too messy for me. For that reason I want to copy the matching files including the parent directory but WITHOUT the non-matching files in that directory.
Input:
user/search/test/sub
user/search/test/sub2
user/search/test/file.pdf
user/search/test/file.doc
user/search/test2/sub
user/search/test2/sub2/file2.pdf
user/search/test2/file3.pdf
user/search/test2/file.doc
Should be copied as
/destination/test/file.pdf
/destination/sub2/file2.pdf
/destination/test2/file3.pdf
EDIT: I don't want to copy the whole path. I don't want my output to be like this:
/destination/test/file.pdf
/destination/test2/sub2/file2.pdf
/destination/test2/file3.pdf
How to do this?