Discussion Locked

How do I search for a file containg text

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I need to know how I can search for all files containing a certain string, and have it output the names of the files.

7 replies

by maxwell edison

I'll assume that you are using a Windows operating system.

Go to Start - Go to Find - Go to Files and Folders. Click on the Advanced Tab. There is a box called "Containing Text" where you can enter the string you're looking for. Direct the find to whatever drive you're searching and click on Find Now. The files that contain that string will be listed for you you to see.

Maxwell

by gigelul

I'm not a linux user but "Midnight Commander" has this ability with find options.

by maxwell edison

Finding files by content (searching for text strings in files):

The standard utilities for searching text strings in files are grep and egrep for regular expression searches and fgrep to search for literal strings. To search for an expression in all files in the current directory just type:

egrep -i "search expression" *

To search for strings in all files down the directory tree you can combine the find or other file name search commands with e.g egrep. This can be done in several ways:

egrep -i "expression" `find . -type f -print`

find . -type f -exec egrep -i "expression" /dev/null {} \;

find . -type f -print | xargs egrep -i "expression"

A small shell script available for download:

http://www.linuxfocus.org/common/src/grepfind.gz

The script makes also sure that non-printable characters are removed in case you egrep accidentally through a binary file.

A very interesting search program is agrep. agrep works basically like egrep but does fault tolerant searches. This way you can also find slightly mis-spelled words. To search for an expression and allow for a maximum of 2 spelling errors you use:

agrep -i -2 "search exprission" *

There is also an available script for that as well.

----------

The preceding answer was found at the following site:

http://www.linuxfocus.org/English/September1998/article64.html

There are additional Linux commands for different variations of these utilities as well as additional links. I might alsoadd that the person who created that Web Site, Guido Socher, did a real nice job. I hope you find it useful.

(REMOVE ALL SPACES from the pasted URLs.)

Maxwell

This discussion is closed to new replies.