LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-15-2006, 08:34 AM   #1
jbillingsle01
LQ Newbie
 
Registered: Nov 2006
Posts: 1

Rep: Reputation: 0
Find some text on harddrive


I would like to search my entire hard drive for some text that appears in regular files. I was given the following command, but I'm not sure it's doing exactly what I wanted. note: I'm trying to search for all the places that my old ip address appeared.

find / -type f -exec grep -H -i 69.69.69.69 {} \; 2>/dev/null

All I get with this results in some obscure files that are hidden or don't really pertain.
 
Old 11-15-2006, 09:55 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
An IP address is a configuration data item. You shouldn't need to search the entire drive; just /etc where configuration files are stored.

Running find as user may produce many *permission denied* messages. Running find as root should not do so.

Su to root.

find /etc -name '*.*' -type f | xargs grep '69.69.69.69'
 
Old 11-15-2006, 09:57 AM   #3
fordeck
Member
 
Registered: Oct 2006
Location: Utah
Posts: 520

Rep: Reputation: 61
Does your machine get it's address via DHCP?

If it does there would be no configuration files that would contain the address. On the other hand, if your machine uses a static address then you would have config files that contain the address. These files are typically under your /etc directory and the commnad line could be changed to:

Code:
find /etc -type f -exec grep -H -i 69.69.69.69 {} \; 2>/dev/null
 
Old 11-15-2006, 01:52 PM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
using -exec with find will be slower than using xargs because a grep process will be spawned for every file found. Using xargs, you'll only spawn one grep process for a large group of files, which can be a lot more efficient, especially if you have a lot of small files.

However the xargs command above will have problems when file names have white-space characters in them. You can ask find to de-limit it's output with the ASCII null character using the -print0 option, and tell xargs to expect this format with the -0 option.

grep will match "." against any character, but you're wanting to say a literal ".". With fixed strings like this, fgrep is slightly more optimised, so it should be preferred for large matches when you're not interested in regular expression patterns.

One more thing, specifiying the -name '*.*' will match all files with a . in. If you want all files, you simply don't need to specify a -name option.

So here's the modified command:
Code:
find / -type f -print0 | xargs -0 fgrep -H '69.69.69.69'
The -H option to fgrep says that the filename will be printed with any matched input line, even if there is only one input file. The input filename is printed by default if there is more than one input file, which is usually going to be the case with find + xargs, but I kept this because there is a small chance that the last invocation of fgrep by xargs might have just one file passed to it.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot find my USB HardDrive noloc45 Linux - Hardware 13 05-14-2006 01:17 AM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
linux 'find' to find text files subu_s Programming 2 12-02-2004 02:56 AM
Can't find the first harddrive under 2.6.7 forkvoid Linux - Hardware 1 08-08-2004 10:04 AM
Mandrake can't find my harddrive IceGrill Linux - Hardware 5 01-24-2003 03:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:13 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration