LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Need to search all files for string - strings command? (https://www.linuxquestions.org/questions/programming-9/need-to-search-all-files-for-string-strings-command-631312/)

jmur 03-28-2008 01:14 PM

Need to search all files for string - strings command?
 
I need to search all files on a server for certain string. I've been told the strings command would be best. I need it to search all files in all directories.

I'm thinking of using the strings command that can do a directory, within a script that does all directories.

I have been a linux user for a while but my scripting and skills are not great.


Thanks

jailbait 03-28-2008 01:17 PM

The grep command may do what you want. See:

man grep

------------------------
Steve Stites

jmur 03-28-2008 01:21 PM

It has to search binary also.
Like say my company has been bought and the old company was called "abcd". Abcd may be in any program file or script. I need to find them all.

I'm experimenting with the strings command, and this will search all files in the current directory for the word "program" and will print the file name. I don't yet know if it's searching all types of files.

strings -af -n 7 * | grep program

colucix 03-28-2008 01:29 PM

An excerpt from the grep man page
Quote:

--binary-files=TYPE
If the first few bytes of a file indicate that the file contains binary data, assume that the file is of
type TYPE. By default, TYPE is binary, and grep normally outputs either a one-line message saying that a
binary file matches, or no message if there is no match.
This is the default behavior. You will only concern about searching into "all files in all directories ". You can use something like
Code:

find / -type f -print 0 | xargs -0 grep <pattern>
This will search <pattern> into all files on your system. It may take a lot of time and resources, anyway. Better to run as root in order to avoid file access permissions problems.

ta0kira 03-28-2008 02:35 PM

Look at sed -i.
ta0kira


All times are GMT -5. The time now is 10:10 PM.