Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a problem; 1) I'm using find command to find directories; 2) I need to execute another find command in previously found directories. I'want something like this find . -type d -not -name bad | xargs find {0} * Is it possible somehow to tell xargs where to put result of the previous command output {0}.

I found a solution by using -exec instead of xargs command: find . -type d -not -name bad -exec find {} -name '*' \;

But I personally more like xargs, is it possible to do that thing with xargs?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

If I understand your requirement correctly, you might be better to do something more akin to:

find . -type d | grep -i <bad> | xargs -i find {} -type f

The pipe through grep is more personal preference - you could keep using the args to find to exclude the directories you aren't interested in. The key thing here is the -i switch to xargs and the use of {} rather than {0}.

share|improve this answer
    
+1 for xargs -i command {} params –  user69817 Jul 19 '11 at 15:26
add comment

find + xargs without using -print0 can be dangerous. See why: http://en.wikipedia.org/wiki/Xargs#The_separator_problem

You may want to use GNU Parallel instead:

find . -type d | grep -i <bad> | parallel find {} -type f

Learn more: http://www.youtube.com/watch?v=OpaiGYxkSuQ

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.