Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

marked as duplicate by jasonwryan, Renan, warl0ck, 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
add comment

1 Answer 1

up vote 4 down vote accepted

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
share|improve this answer
    
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
add comment

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