I have a directory containing a large number of PDF files, some of which are in subdirectories (which can extend several layers deep). I would like to move all files matching *.pdf
into a single output folder named papers
.
How can I do this?
If you use bash
in a recent version, you can profit from the globstar
option:
shopt -s globstar
mv **/*.pdf papers/
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
"{}"
to deal with file names containing spaces?
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.
-print0
to your find, and -0
to xargs.
Sep 20, 2012 at 20:00
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
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.
a/x.pdf
andb/x.pdf
?