UNIX Commands

Suppose you have recorded some infomation in a file but you forget what is the name of the file and where you have placed the file. This command will look at the contents of files to find the information you want.


Suppose your present working directory is /home/joe , and you want to look for the string "informa" in all files inside /home/joe , incliuding all subfolders.

[joe@server /joe]$ grep -r infoma *

This command tells the computer to look the string "informa" in all files inside /home/joe , including the files inside all subfolders. (The "-r" specifies subdirectories should be searched. The "*" specifies that all files are searched.)

Possible output:

password.txt: This file contains sensitive information.
htdocs/contact.html: Further information can be found at
htdocs/support/more.html: research purposes, informative material can be found

In this case, there are 3 instances where the string "informa" appears.
One is at /home/joe/password.txt ,
another at /home/joe/htdocs/contact.html ,
and one more at /home/joe/htdocs/support/more.html