Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help please - cp and regex

Status
Not open for further replies.
Jan 26, 2004
18
US
Hi all, I have a very large directory of files of differing types and I need to seperate them based on file type. For example, I need to copy all of the pdfs into a temp directory. I tried this but got an error
unix-shell:# cp *.pdf temp_pdf_dir/
bash: /bin/cp: Argument list too long

Can anyone help me, Im new to regular expressions and am not having any luck.

Thanks in advance
 
Try something like this:
echo *.pdf | while read pdf
do cp "$pdf" temp_pdf_dir
done


Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
If you get the same error with the PHV solution, try :
[tt]
find \( ! -name . -prune \) \( -name '*.pdf' -print \) | while read pdf
do
cp $pdf temp_pdf_dir/
done
[/tt]

Jean Pierre.
 
or:

ls *.pdf | xargs cp {} temp_pdf_dir/

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
vgersh99, I guess you'll raise this:
bash: /bin/ls: Argument list too long

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks to all for their input. cp was dying because the list of pdf files was too great to it puked and died. This is the command I eventually came up with.

find . -iname '*.pdf' -print0 | xargs -0 -n 1 cp --target-directory=temp_pdf_dir/

Thanks again to all that helped out. Your the best.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top