R-Ts NetWorks

Server the Best

How to find files containing a specific word ?


How to find files containing a specific word and store the results in another text file ?

Solution :

Use the following command :

grep -R word /directory/* > filename

Use -iR instead of -R for case insensitive search.
This approach will take some time depending on the size and number of files.

A faster method is to use the locate command.

First run the following command to create/update the search database:

updatedb

Then run the following command :

locate string > results.txt

Advertisements

October 13, 2012 - Posted by | Linux

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: