First page Back Continue Last page Overview Graphics
Searching the contents of text files
To search for the string “program” in a file
- $ grep program /usr/share/doc/whois/README
Useful grep switches (parameters)
- $ grep -R : search recursively the entire directory
- $ grep -n : show the line number of any matches
- $ grep -A 5 : show me 5 lines AFTER the match
- $ grep -f <file> : read search patterns from <file>
- $ grep -v : do not show matching lines
Notes:
grep is an extremely powerful tool. If you remember something mentioned in a file, but don't remember what that file was called, or where it was, you can search entire directories (recursively) for a string.
$ grep -R “I seem to forget” *
...will search all contents of the current directory, and its sub-directories, for files that contain the string “I seem to forget”