Possible Duplicate:
Arg list too long error while using find

I try to find many files in many folders with specific content, and delete them.

find dir.*/* -exec grep -l "content" {} \; | xargs rm -f

And I get following message:

-bash: /bin/find: Argument list too long

Can you help me?

marked as duplicate by jasonwryan, Renan, daisy, Mat, Kevin Sep 24 '12 at 2:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Why find dir.*/* instead of find dir.*? Is it intentional? Do you want to ommit dotflles/dotdirs in dir.* and/or include symlinks in dir.*? – Stéphane Chazelas Aug 30 '12 at 20:01
  • consider if you really need to search dir.*/*, maybe just . would be appropriate? find will (by default) act recursively – lk- Aug 30 '12 at 20:02
  • Thank you for your answers. I don't need symlinks in find results. – Webeith Aug 30 '12 at 20:09
  • @jasonwryan Thank for your answer, I use following code: find dir.*/. ! -name . -prune -name '*' -exec grep -l "content" {} \; | xargs rm -f – Webeith Aug 30 '12 at 20:13

Let find itself perform the recursion. Also, don't use xargs: its input format is not compatible with the output format of find. If you have GNU find or FreeBSD/NetBSD/OSX find, it has everything you need built in.

find dir.* -mindepth 2 -type f -exec grep -q "content" {} \; -delete
  • In the rare case that find might not suffice, you can use -print0 and --null, respectively: find somedir -somefilters ... -print0 | xargs --null someexec. I am not sure about the differences between GNU and POSIX commands, though. – fheub Aug 31 '12 at 7:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.