find

The basic idea is simple: Do a recursive traveral of the files hierachy starting with a directory. Whenever a file or directory is visited, perform a specified action on the node you are visiting. The action is specified with a boolean expression.

The problem is doing this from a shell command. These boolean expressions will be ugly.

The boolean operators

You probably noticed in CSCI 181 or 182 or 255 that you needed three boolean operators: AND (&&), OR (||), and NOT (!).

These are all present in find but are expressed differently.

  • You can also use parenthesis to override the usual precendence rules. This can get ugly when you go this from the shell because the shell has its on special interpretation of (, ) and !. This means that when you want to say
        find ( α -o ! β ) &gamma
    you must type
        find \( α -o \! β \) &gamma
    Be sure to surround all of those operators with spaces.

    Examples

    Unfortunately, the terms of the find command are many and difficult. So let’s just go to a collection of Unix/Linux find command examples and try some of them out.