Re: find command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Mar 23, 2004 at 02:43:56AM -0800, IAK Tanoli wrote:
> 
> find ./ -name <filename> -depth -print | grep "text"

That will find files with *names* containing the
string "text". If you want to search the *contents*
of the file, you need to use the -exec construct,
e.g. 

  find . -type f -depth -exec grep -H "text" \{\} \;

The -H argument to grep will force it to print
out the matching filename in question.

Alternatively, if one just wants to recursively
search for a string in all files under a directory,
it can be easier to use the -r switch on (GNU) grep.
The following command will have pretty much the same
effect as the previous find command:

  grep -ri "text" .

OTOH, the find command gives you much more control
over which files will be searched, so that if for
example you wanted to search only files with names
ending in ".txt", 

  find . -name \*.txt -type f -depth -exec grep -H "text" \{\} \;

should do the trick.

--Bob


-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux