How can I recursively copy all pdf files in a directory (and it's subdirectories) into a single output directory?
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Peaceful Mind
--
Chapters
00:00 How Can I Recursively Copy All Pdf Files In A Directory (And It'S Subdirectories) Into A Single
00:31 Answer 1 Score 31
00:55 Accepted Answer Score 23
01:07 Answer 3 Score 4
01:32 Answer 4 Score 0
01:48 Answer 5 Score 0
02:08 Thank you
--
Full question
https://superuser.com/questions/477480/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #commandline
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Peaceful Mind
--
Chapters
00:00 How Can I Recursively Copy All Pdf Files In A Directory (And It'S Subdirectories) Into A Single
00:31 Answer 1 Score 31
00:55 Accepted Answer Score 23
01:07 Answer 3 Score 4
01:32 Answer 4 Score 0
01:48 Answer 5 Score 0
02:08 Thank you
--
Full question
https://superuser.com/questions/477480/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #commandline
#avk47
ANSWER 1
Score 31
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
ACCEPTED ANSWER
Score 23
If you use bash
in a recent version, you can profit from the globstar
option:
shopt -s globstar
mv **/*.pdf papers/
ANSWER 3
Score 4
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.
ANSWER 4
Score 0
For the Windows command line (cmd.exe), you can use:
for /F "usebackq delims==" %j IN (`dir /s /b *.pdf`) do copy "%j" c:\target_dir
ANSWER 5
Score 0
If you're only searching one directory deep, you could do:
mkdir <destination>
mv */*.pdf <destination>
where <destination>
stands for some directory. mv
will not automatically create a directory for you.