How can I recursively copy all pdf files in a directory (and it's subdirectories) into a single output directory?
find /bunchopdfs -name "*.pdf" -exec mv {} /papers \;
Here's a test I did
$ ls -R
.:
a aaa bbb.pdf pdfs
./a:
foo.pdf
./pdfs:
Notice the file "aaa bbb.pdf".
$ find . -name "*pdf" -exec mv {} pdfs \;
$ ls -R
.:
a pdfs
./a:
./pdfs:
aaa bbb.pdf foo.pdf
If you use bash
in a recent version, you can profit from the globstar
option:
shopt -s globstar
mv **/*.pdf papers/
find -print0 /directory/with/pdfs -iname "*.pdf" | xargs -0 mv -t /papers
(similar to another answer but I prefer pipe/xargs/mv ... more intuitive for me)
FYI, I did the above one-line script successfully on multiple directories and multiple pdf files.