41

How can I find all the files ending with .sh OR .bin in a given folder.

I know I can do:

find /path/to/folder -name "*.bin"

to find all bin file. What must I add to also look for .sh files ?

Manuel Selva
  • 18,554
  • 22
  • 89
  • 134

1 Answers1

58

The manual page tells you that -o is the OR operator. If you want case insensitivity, use iname instead of name.

find /path/to/folder -iname "*.bin" -o -iname "*.sh"
Benoit
  • 76,634
  • 23
  • 210
  • 236
  • 1
    Are '.SH' and '.sH' and '.Sh' files the same as '.sh' files? – Jonathan Leffler Oct 28 '10 at 06:37
  • 4
    Also, note that on some systems (Solaris 10, for example) you need to use `find /path/to/folder -name '*.bin' -print -o -name '*.sh' -print` with two explicit print options. – Jonathan Leffler Oct 28 '10 at 06:39
  • you're right, in UNIX systems, script shells usually have a lower case extension. This is however not a rule that I know of. – Benoit Oct 28 '10 at 06:44
  • @Jonathan: wouldn't most accept `find /path/to/folder \( -name '*.bin' -o -name '*.sh' \) -print`? – Hasturkun Oct 28 '10 at 08:07
  • @Hasturkun : Probably, but you must take care of escaping the parentheses so that you shell does not interpret them. So, `find /path \( -name '*.bin' -o -name '*.sh' \) -print` (assuming bash). Using a find port under Windows with cmd, no need to escape those parens, nor stars. – Benoit Oct 28 '10 at 08:24
  • @Benoit: I actually did escape them... it looks like SO turns `\\(` to `\(` (maybe I should complain about this on meta...) – Hasturkun Oct 28 '10 at 09:44
  • @Hasturkan: most versions of `find` would accept your invocation with '`\\(`' and '`\\)`' as already discussed and explained (and SO markup has definitely been changed again). POSIX requires the 'default print' clause - but I checked on Solaris 10 that the version you stated does not work as written. I've been bitten by that before. – Jonathan Leffler Oct 28 '10 at 12:05