Wednesday, August 3, 2011

find command to exclude filename and case sensitivity


For the find command to exclude filenames in Linux use "-not" option or "!" option

For example:
find . -name "*".pl  -not -name "*".sh -type f

will list all the files ending with ".pl" and exlude all the files ending with ".sh"

In Linux we can also use -iname option if we want to exclude the case sensitivity for the searches.In that
case if we use
find . -iname "*".pl  -not -iname "*".sh -type f
will list all the files ending with ".pl" ,".PL"... and exlude all the files ending with ".sh",".SH" ....



In solaris "-not option will not work and so we should use only "!" option.

For example:
find . -name "*".pl ! -name "*".sh -type f
will list all the files ending with ".pl" and exlude all the files ending with ".sh"

In solaris -iname option also cannot be used.