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 think I can keep my question short. Why does the following command produce no output?

find /usr/share/themes -mindepth 1 -maxdepth 1 -type d -execdir test -d {}/gnome-shell \;

I expected it to print all folders in /usr/share/themes that contain a folder gnome-shell. Several websites suggest that this usage of test as a command in exec/execdir is possible.

From man find:

-exec command ;
              Execute  command;  true  if 0 status is returned. [...]
share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

–exec and –execdir evaluate to true if the named program returns a 0 value as its exit status.

This means that, if you were to say something like –execdir test -d {}/gnome-shell \; –print or –exec … \; –something, the thing after the –exec would be processed if and only if the test command returned true.  As an extreme example, you could even say

find starting_dir … –execdir test –d {}/gnome-shell \; –exec rm –rf {} \;

although that’s not necessarily the best way to do that.

share|improve this answer
    
Thank you very much for the explanation. find /usr/share/themes -mindepth 1 -maxdepth 1 -type d -execdir test -d {}/gnome-shell \; -print does the job. –  slosd Oct 25 '12 at 8:36
add comment

test does not output anything, it just returns the exit status.

However, if you are only testing in depth 1, you can avoid find completely:

ls -d /usr/share/themes/*/gnome-shell
share|improve this answer
    
I know that it just returns an exit status, but I think -exec checks that exit status (see my addition of the find man page in the question). As far as I know ls should not be used when the output is used as input for another command since it might print additional information or format the output. –  slosd Oct 24 '12 at 22:40
    
@slosd: So search in depth 2 for gnome-shell and use the "another command" in execdir. –  choroba Oct 24 '12 at 22:46
1  
Good idea. find /usr/share/themes -mindepth 2 -maxdepth 2 -type d -name gnome-shell -execdir pwd \; produces what I want. –  slosd Oct 24 '12 at 22:59
add comment

Your Answer

 
discard

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

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