Copy specific file type keeping the folder structure

cp

I have a folder structure with a bunch of *.csv files scattered across the folders. Now I want to copy all *.csv files to another destination keeping the folder structure.

It works by doing:

cp --parents *.csv /target
cp --parents */*.csv" /target
cp --parents */*/*.csv /target
cp --parents */*/*/*.csv /target
...

and so on, but I would like to do it using one command.

Best Answer

find has a very handy -exec option:

find . -name '*.csv' -exec cp --parents \{\} /target \;
Related Question