Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-28-2008, 01:14 PM   #1
LQ Newbie
Registered: Jul 2006
Distribution: Fedora 14
Posts: 2

Rep: Reputation: 0
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.

Old 03-28-2008, 01:17 PM   #2
LQ Guru
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Linux Mint 17, Debian 8
Posts: 7,863

Rep: Reputation: 311Reputation: 311Reputation: 311Reputation: 311
The grep command may do what you want. See:

man grep

Steve Stites
Old 03-28-2008, 01:21 PM   #3
LQ Newbie
Registered: Jul 2006
Distribution: Fedora 14
Posts: 2

Original Poster
Rep: Reputation: 0
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

Last edited by jmur; 03-28-2008 at 01:33 PM.
Old 03-28-2008, 01:29 PM   #4
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
An excerpt from the grep man page
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
 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.
Old 03-28-2008, 02:35 PM   #5
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Look at sed -i.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
vim 'n' lynx: command line option to search for string Samsara Linux - Software 6 01-02-2013 06:36 PM
Issuing find command to search for string keysorsoze Linux - Newbie 4 11-30-2007 12:06 AM
Search and replace string in executable files aalex77 Programming 2 05-26-2006 06:32 PM
Is it possible to search for a string from all the files on the harddisk? Akhran Linux - Newbie 8 09-13-2005 06:09 AM
how do i search files for a particular string? darkpark Linux - Newbie 4 07-05-2005 05:46 PM > Forums > Non-*NIX Forums > Programming

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration