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
  • 27,531
  • 11
  • 97
  • 118
Vicky Dev
  • 442
  • 1
  • 6
  • 23
  • Similar: [How to remove files using find's multiple -name parameter?](http://superuser.com/q/977317/87805) – kenorb May 18 '16 at 19:51

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
  • 27,531
  • 11
  • 97
  • 118
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

Yves Dorfsman
  • 225
  • 1
  • 4