2

There are parameters of find command for finding files and directories respectively -f and -d, but I want to avoid writing two find commands and && or || between them.

I want to find file or directory(whichever is found conditionally) in one command, can -d and -f be ORed ?

Steven
  • 28,386
Vicky Dev
  • 492

2 Answers2

2

Use the -o option.

From the find man page (under the OPERATORS heading):

   expr1 -o expr2
          Or; expr2 is not evaluated if expr1 is true.
Steven
  • 28,386
2

If you don't specify -f nor -d, find with show you all types of inodes (files, directories, devices, link etc...). If you want files and directories only, then use -o, and possibly use escaped parenthesis if you are going to use other type of conditins.

For example, all files, directories, links etc.... which have been modified/created in the past 2 days:

find . -iname '*blah*' -mtime -2

Same as above, but files and directory exclusively (no sym links, devices...)

find . -iname '*blah*' \( -type d -o -type f \) -mtime -2