Re: simple grep command....

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

 



Bruce Douglas wrote:
> A simple question... trying to do a search for a string in a file...
> i don't know where on my harddrive the file is, nor do i know the
> name!! thought the command should be something like:
> #grep -F -r "string" /

Searching for strings is probably best done through "strings" the command.
That said, to search _all_ files on your system, use find and xargs:

( find / -type f -print | xargs strings --print-file-name ) | grep
"what-to-find"

The reason you want to use "strings" is that it only returns printable
characters and makes the output so much easier to understand. Of course if
you just want to know if there is a hit or not in a file, grep is able to
just return the filename if it finds a hit in there - in that case you don't
need strings at all, but you will not know the context if found the hit
within.

Be careful with find - if you have circular symbolic links it goes
"bananas" - and you'll need to expand your find command with the --prune
argument in the right places. Otherwise it just loops around and never
terminates (it stack dumps when the path becomes way to long).

Also, depending on what type of file, there are better tools than strings to
for instance search in libraries, for symbolic information etc. - it helps
knowing what you're looking for and context.

Good luck!

Best Regards
 Peter Larsen



-- 
Psyche-list mailing list
Psyche-list@redhat.com
https://listman.redhat.com/mailman/listinfo/psyche-list

[Index of Archives]     [Fedora General Discussion]     [Red Hat General Discussion]     [Centos]     [Kernel]     [Red Hat Install]     [Red Hat Watch]     [Red Hat Development]     [Red Hat 9]     [Gimp]     [Yosemite News]

  Powered by Linux