next up previous
Next: Compressing and Encrypting Files Up: USING UNIX Previous: Checking Spelling (spellispell)

Searching For and Inside Files (find, grep)

The command find is used to find files with various attributes. It has many options. This makes it somewhat awkward for just searching for a file by name. For example, the command
find . -name "*.tex" -print
finds all the files in the current directory and any directories below that have a name which ends in .tex and then prints the result of the search at the terminal.

The program grep looks inside files for specified text. For example,
grep Diophantine paper.tex
will search the file paper.tex for any occurrences of the text ``Diophantine'' and then then print those lines at the terminal. If you are searching in more than one file as in grep Diophantine *.tex it will print the name of the file in which the line was found.