|
|
Find data within files on unix and linux
This document should help provide the necessary information to assist in performing searches within text files on linux and unix systems.
- Replace the parameters in bold with your criteria.
Note the trailing semi-colon ";" after the slash "\" slash and yes there is a space after the last curly bracket "}"
find /directory -name \*.log -exec grep -l "string to find" {} \;
- Example 1: Search for an IP address
find /log_filesystem -name \*.log -exec grep "172.16.3.50" {} \;
Results are as follows:
172.16.3.50 - - [06/Mar/2005:11:35:37 -0500] "TRACE / HTTP/1.0" 403 1078 "-" "-"
172.16.3.50 - - [11/Oct/2005:21:53:46 -0400] "GET / HTTP/1.0" 200 13473 "-" "-"
- Example 2: Search for a string called Serial in the directory "/web_filesystem/"
find /web_filesystem/ -name \* -exec grep -l "Serial" {} \;
Results are as follows:
/web_filesystem/site1/content/learning/index.html
/web_filesystem/site1/content/learning/Serial-console.html
|
|
|