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


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

  • The additional explanation with the parenthesis gave you the win, because that would have been my next problem. Thanks for reading my mind. – erik Aug 17 '15 at 19:03

Try this:

find -type f -o -type l

You can combine the predicates using -a (for and) or -o (for or). So, you can type

find /path -type f -o -type l

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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