I am trying to copy all .odt
files including those in subdirectories.
cp -r ~/Documents/* ~/copies # works as expected
cp -r ~/Documents/*.odt ~/copies # does not work as expected
The first line will copy all files and in all subdirectories but the second will copy only the .odt
files in ~/Documents
and none of the files in the subdirectories.
Best Answer
If you wish to replicate the directory structure (more like what
cp -r
does as suggested by steeldriver) but only populate it with the.odt
files, you can do it withrsync
, where-f
is the 'filter' option. The other options are more straight-forward. You find all the options inman rsync
.It is a good idea to use the 'dry run' option
-n
and the verbose option-v
in order to see what will be done before running the real command (whenn
is removed from the command line).