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.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityHere is the command you can use:
find -type f -or -type d
. I get an error..
find: paths must precede expression:`.. Any idea why?
Jul 1, 2018 at 21:38
tl:dr
use find . -name "*string*" -type f -o -name "*string*" -type d
explanation
the -o command or
s 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.
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).
GNU find
version 4.7.0.. It doesn't seem to support ,
. The error message says that find: Arguments to -type should contain only one letter.
Jul 1, 2018 at 21:37
-type f -or -type d
or POSIX version -type f -o -type d
seems to ignore my ! -path
parameter a.k.a. -not -path
... Beware to anyone who combines these two parameters, because you might accidentally find/delete files. Use -type d,f
instead...
Jan 15, 2021 at 21:33
find ... -not -path ... \( -type f -o -type d \)
. If you don't specify an operator then -a
(AND) is implied. Since AND binds more tightly, you end up with unexpected behavior in your case.
find
command using that syntax results in this error on Ubuntu:find: Must separate multiple arguments to -type using: ','
... for Google.