Skip to Content
Linux in a Nutshell, 6th Edition
book

Linux in a Nutshell, 6th Edition

by Ellen Siever, Stephen Figgins, Robert Love, Arnold Robbins
September 2009
Beginner
942 pages
85h 34m
English
O'Reilly Media, Inc.
Content preview from Linux in a Nutshell, 6th Edition

Name

grep

Synopsis

git grep [-e] pattern [--cached|commit ...] [-- path ...]

Search the given commits for the given regular expression pattern(s).

If no commits are specified, normally searches the current work tree. With --cached, searches the index instead. If paths are specified, restricts the search to the given files or directories.

The main advantage of git grep over plain grep is that it ignores files (such as compiler output and editor backups) that have not been added with git add.

When multiple patterns are specified (using -e), the default combination is --or, unless --and or --not is specified.

Options

-e pattern
--and
--or
--not
(
)
-E (act like egrep)
-F (act like fgrep)
-i, --ignore-case
-v, --invert-match
-w, --word-regexp
-l, --files-with-matches
-L, --files-without-matches

Examples

To search the work tree for lines containing chicken without considering case:

$ git grep -i chicken

To search the top of branches test1 and test2 for lines containing alpha and either beta or gamma:

$ git grep -e alpha --and \( -e beta -e gamma \) test1 test2

To search only the mylib directory for files starting with the word chicken:

$ git grep '^chicken' -- mylib
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Unix in a Nutshell, 4th Edition

Unix in a Nutshell, 4th Edition

Arnold Robbins
Linux Under the Hood

Linux Under the Hood

Sander van Vugt
Linux Kernel in a Nutshell

Linux Kernel in a Nutshell

Greg Kroah-Hartman

Publisher Resources

ISBN: 9780596806088Errata Page