LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 03-28-2008, 01:14 PM   #1
jmur
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.


Thanks
 
Old 03-28-2008, 01:17 PM   #2
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,508

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

man grep

------------------------
Steve Stites
 
Old 03-28-2008, 01:21 PM   #3
jmur
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
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,488

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
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.
 
Old 03-28-2008, 02:35 PM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Look at sed -i.
ta0kira
 
  


Reply


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


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

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