I want to copy all files of a said type on my external hard drive

My code is this, what I'm trying to accomplish is to make a list of all pdf documents in my computer and then copy all of those documents to my external hard drive in a directory

mkdir /Volumes/Hardrive-1/allpdf
 
echo "File Locations" > /Volumes/Hardrive-1/allpdf/FileLocations.txt
mdfind pdf >> /Volumes/Hardrive-1/allpdf/FileLocations.txt
 
find ~/ -iname "*.pdf" -exec cp {} /Volumes/Hardrive-1/allpdf/ \;

When i compile the code and test it, it creates the "allpdf" directory and creates the "FileLocations.txt" file with all the files that contain "pdf" in their names or extensions, but the last part of my code seems to be unable to work and all I get is a "bad path" perhas there's a mistake somewhere? thanks in advance

Try:

find ~/ -iname "*.pdf" -print0 | xargs -0 cp -t "/Volumes/Hardrive-1/allpdf/"

It doesn't work and only returns this :frowning: :

mkdir: /Volumes/D-MEM/D: File exists
find: /Users/my_username//Library/Application Support/Firefox/Profiles/na6g9efh.default/jetpack: Permission denied
find: /Users/my_username//Library/Saved Application State/com.adobe.flashplayer.installmanager.savedState: Permission denied