How to "find" both regular files and directories?

How can I tell ( if I can tell !) find to find files of both the directory and file type?

find -type fd

It is like the heuristic dark ages up in here.

Asked By: James Andino

||

Here is the command you can use:

find -type f -or -type d
Answered By: laebshade

tl:dr

use find . -name "*string*" -type f -o -name "*string*" -type d

explanation

the -o command ors the arguments after the filepath completely, such that find . -name "*string*" -type f -o -type d computes find . (-name "*string*" -type f) -o (-type d). For this reason, you must specify the

Most users will want something that looks like

find . -name  "*string*" -type f -o -name "*string*" -type d

which computes as

find . (-name  "*string*" -type f) -o (-name "*string*" -type d)

find syntax details

-name "*string*" searches for names that contain the string string anywhere in them.

Answered By: Ulad Kasach

If you’re using the GNU find then the following solution might suit you:

find -type d,f

See man find for more details:

To search for more than one type at once, you can supply the combined list of type letters separated by a comma , (GNU extension).

Answered By: Mateusz Piotrowski
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.