Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .