GNU Find – How to Search for Multiple File Types

find

How is it possible to use the GNU find command to match several file types at a time (one search command)?

The man page says:

-type c
    File is of type c:
    b      block (buffered) special
    c      character (unbuffered) special
    d      directory
    p      named pipe (FIFO)
    f      regular file
    l      symbolic link; this is never true if the -L option or the -follow
           option  is in  effect,  unless  the  symbolic link is broken.  If
           you want to search for symbolic links when -L is in effect, use
           -xtype.
    s      socket
    D      door (Solaris)

and I want to search for files (f) and symbolic links (l) and pipe it to another process. How can I search for both at the same time?

I have tried

find -type fl | …
find -type f -type l | …
find -xtype f -type l | …

I know a workaround would be to use a subshell

(find -type f; find -type l) | …

but I just want to know if it is possible.

Best Answer

You can group and use logical operators with find, but you have to escape the parens so you could look for all files and links like

find \( -type f -o -type l \) <other filters>

so if you wanted all files and links whose name starts with t you could do

find \( -type f -o -type l \) -name 't*'

You only need the parens if you want to group things and combine with other opeators, so if you have no other search criteria you can omit them

Related Question