3

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. [...]

2 Answers 2

4

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

1
  • 1
    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, 2012 at 8:36
1

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
3
  • 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, 2012 at 22:40
  • @slosd: So search in depth 2 for gnome-shell and use the "another command" in execdir.
    – choroba
    Oct 24, 2012 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, 2012 at 22:59

You must log in to answer this question.

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