tags:

views:

46

answers:

1

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 ?

+6  A: 

Hello. 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
Are '.SH' and '.sH' and '.Sh' files the same as '.sh' files?
Jonathan Leffler
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
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
@Jonathan: wouldn't most accept `find /path/to/folder \( -name '*.bin' -o -name '*.sh' \) -print`?
Hasturkun
@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
@Benoit: I actually did escape them... it looks like SO turns `\\(` to `\(` (maybe I should complain about this on meta...)
Hasturkun
wow, you are right :)
Benoit
@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