LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   finding files (http://www.linuxquestions.org/questions/linux-newbie-8/finding-files-574955/)

nmansour 08-05-2007 08:54 PM

finding files
 
Hi,

If I want to find all files on my box which contain a certain word, what should I do?

Thanks,

Noha

anomie 08-05-2007 09:03 PM

Quote:

Originally Posted by nmansour
files on my box which contain a certain word...

In the filename itself, or in the contents (of, say, an ascii text file)? ;)

If the former, find or locate (if installed) will do it.

If the latter, a recursive grep from the appropriate starting point will do it.

Four 08-05-2007 09:33 PM

I would like to know how to search inside files. But for using find do this

list files of "filename"
find /directory/where/you/want/to/search/ -type f | grep "filename"

List directories of "filename"
find /directory/where/you/want/to/search/ -type d | grep "filename"

bigrigdriver 08-05-2007 09:44 PM

Quote:

If I want to find all files on my box which contain a certain word, what should I do?
find / -type f | xargs grep "search string"

You will have to run it as root because of the many directories/files to which the normal user doesn't have access.
Replace "search string" with the word/phrase you want to find.

syg00 08-05-2007 10:10 PM

Also use -H on the greps

nmansour 08-06-2007 12:32 AM

This is the command I used, and this is what I was given, what does this mean?

find / -type f | xargs grep -H "million"
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

Noha

Fond_of_Opensource 08-06-2007 06:27 AM

Use this command.


# find / -exec -H grep "your_pattern_string" {} \;

nmansour 08-06-2007 08:54 AM

I did not find the file which contains the word "million".
It is a regular file and I am sure it is somewhere in my box.

Thanks,

Noha

anomie 08-06-2007 09:07 AM

Quote:

Originally Posted by nmansour
I did not find the file which contains the word "million".
It is a regular file and I am sure it is somewhere in my box.

A 'regular' file in that it's an ascii text file? (As opposed to a binary OOo or abiword doc?)

If you have no clue where it could be, I'd use:
# grep -IRHi 'million' /*

If you have some idea about which subdirectory it would be under, that'll speed the search up for you.

colucix 08-06-2007 09:11 AM

Maybe the word "million" is not lower-case? Following one of the examples above, you can try
Code:

find / -type f -exec grep -Hiw million {} \;
See man grep for details about -i and -w options. Searching from / can take a long time, yet. Hope this helps.


All times are GMT -5. The time now is 09:59 AM.