There are several methods for finding files and text within files from a terminal. Table A.6 contains the more common methods used.
Table A.6. Commands Used to Find Files and Text Within Files
COMMAND
GENERAL USAGE
DESCRIPTION
egrep
egrep [OPTIONS] PATTERN [FILE]
Searches the contexts of text files for the specified pattern. The pattern specified for egrep must be created using extended regular expressions.
Common options include
-i Ignore case for searches
-r Recursive search for matching files
For example:
egrep (root|admin) /etc/*
Syntax for extended regular expressions is available in Table A.8.
fgrep
fgrep [OPTIONS] PATTERN [FILE]
Searches the contexts of text files for the specified pattern. The pattern specified for fgrep will be interpreted literally and not translated as a regular expression. This allows for searching on such things as wildcard characters (*, ?).
Common options include
-i Ignore case for searches
-r Recursive search for matching files
For example:
fgrep '*/15' /etc/crontab
find
find [PATH] EXPRESSION
Searches a directory structure for as pecific file or files matching the specified expression.
Common expression options include
-name File name search
-type File type search
-uid File owner UID search
For example:
find /etc -name pass
grep
grep [OPTIONS] PATTERN [FILE]
Searches the contexts of text files for the specified pattern. The pattern specified for grep must be created using common regular expressions.
Common options include
-i Ignore case for searches
-r Recursive search for matching files
For example:
grep ^root /etc/*
Syntax for common regular expressions is available in Table A.7.
locate
locate PATTERN
Searches the locatedb database for all instances of the specified pattern. Using locate is typically faster than find for filesystem-wide searches. However, unless updatedb is used to update the locatedb database, new files will not be contained in the database.
updatedb
updatedb
Scans the local filesystem and ensures that all filenames are contained in the locatedb database.
whereis
whereis NAME
Locates the binary, source code, and manual pages for the specified command.
which
which NAME
Searches your PATH for the specified command and returns the location of the first instance of that command.