Find, Search, Grep files#

How do I find a file?#

Shell#

$ find /path -name 'program.c' 2>/dev/null

This finds all files from the current directory on down with JavaScript and OReilly in the name

$ find . \( -name "*JavaScript*" -a -name "*OReilly*" \) | more

These find all files from the current directory on down with Java and not JavaScript in the name

$ find . \( -name "*Java*" -a ! -name "*JavaScript*" \)
$ find . \( -name "*Java*" -a -not -name "*JavaScript*" \)

Search through specific file types#

grep#

To recursively search through specific file types for a string, use

$ grep -ircls --include=*.{pl,sh,bsh,csh,py} "some_string" /some/path

ack#

Is is much better than grep.

To search recursively through only python scripts for foo -

$ ack --python foo

By default ack skips backup and log files. Very nice.

zgrep#

Search possibly compressed files for a regular expression


Linux.Shell - Mac.Shell