I need to list all files that refer to my network-name, but I can't work out a command to do it. I thought I would have to cat everything, piping through grep 'string', but that doesn't search recursively, the help-file doesn't show a recursive flag, and I'm not sure that it would actually give me the filenames anyway.
Help, please?
Anne
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Anne Wilson wrote:
I need to list all files that refer to my network-name, but I can't work out a command to do it. I thought I would have to cat everything, piping through grep 'string', but that doesn't search recursively, the help-file doesn't show a recursive flag, and I'm not sure that it would actually give me the filenames anyway.
Help, please?
Anne
Why not use grep .... it allows searching recursively.
Look at the man pages.
James Kosin
On Wed, Feb 01, 2006 at 04:42:19PM +0000, Anne Wilson wrote:
I need to list all files that refer to my network-name, but I can't work out a command to do it. I thought I would have to cat everything, piping through grep 'string', but that doesn't search recursively, the help-file doesn't show a recursive flag, and I'm not sure that it would actually give me the filenames anyway.
Help, please?
Anne
Registered Linux User No.293302 (http://counter.li.org/)
Do this as root.
To see a list of filenames containing the target string:
find / -name * -exec grep -l 'put your string here' {} ;
if you want to see the actual file content containing the string, simply remove the -l option from grep.
Fred
On Wed, 1 Feb 2006, fredex wrote:
On Wed, Feb 01, 2006 at 04:42:19PM +0000, Anne Wilson wrote:
I need to list all files that refer to my network-name, but I can't work out a command to do it. I thought I would have to cat everything, piping through grep 'string', but that doesn't search recursively, the help-file doesn't show a recursive flag, and I'm not sure that it would actually give me the filenames anyway.
Help, please?
Anne
Registered Linux User No.293302 (http://counter.li.org/)
Do this as root.
To see a list of filenames containing the target string:
find / -name * -exec grep -l 'put your string here' {} ;
if you want to see the actual file content containing the string, simply remove the -l option from grep.
"grep" works recursively, you know.
rday
On Wed, 2006-02-01 at 11:46 -0500, Robert P. J. Day wrote:
On Wed, 1 Feb 2006, fredex wrote:
On Wed, Feb 01, 2006 at 04:42:19PM +0000, Anne Wilson wrote:
I need to list all files that refer to my network-name, but I can't work out a command to do it. I thought I would have to cat everything, piping through grep 'string', but that doesn't search recursively, the help-file doesn't show a recursive flag, and I'm not sure that it would actually give me the filenames anyway.
Help, please?
Anne
Registered Linux User No.293302 (http://counter.li.org/)
Do this as root.
To see a list of filenames containing the target string:
find / -name * -exec grep -l 'put your string here' {} ;
if you want to see the actual file content containing the string, simply remove the -l option from grep.
"grep" works recursively, you know.
rday
How about this:
$du -a <PATH> | grep <FILE>
This works well for me.
On Wednesday 01 Feb 2006 20:41, CodeHeads wrote:
How about this:
$du -a <PATH> | grep <FILE>
This works well for me.
That returns files with the string in the name, I believe. I need files with the string in the body.
Anne
On Wed, 2006-02-01 at 20:49 +0000, Anne Wilson wrote:
On Wednesday 01 Feb 2006 20:41, CodeHeads wrote:
How about this:
$du -a <PATH> | grep <FILE>
This works well for me.
That returns files with the string in the name, I believe. I need files with the string in the body.
Anne
oooppss sorry Anne :) I was confused. LOL
On Wed, Feb 01, 2006 at 04:22:07PM -0500, CodeHeads wrote:
On Wed, 2006-02-01 at 20:49 +0000, Anne Wilson wrote:
On Wednesday 01 Feb 2006 20:41, CodeHeads wrote:
How about this:
$du -a <PATH> | grep <FILE>
This works well for me.
That returns files with the string in the name, I believe. I need files with the string in the body.
Anne
oooppss sorry Anne :) I was confused. LOL
I had two suggestions: 1. gnome-search-tool 2. find ./ -name "*" -exec grep "string" {} /dev/null ;
Someone suggested even a better command solution than 2. above but I can't remember what it is.
On Wed, 2006-02-01 at 16:31, akonstam@trinity.edu wrote:
--
I had two suggestions:
- gnome-search-tool
- find ./ -name "*" -exec grep "string" {} /dev/null ;
Someone suggested even a better command solution than 2. above but I can't remember what it is. --
find . -type f -print0 |xargs -0 grep "string"
should work.
I had two suggestions:
- gnome-search-tool
- find ./ -name "*" -exec grep "string" {} /dev/null ;
Someone suggested even a better command solution than 2. above but I can't remember what it is. --
find . -type f -print0 |xargs -0 grep "string"
should work.
..err...my sugestion is much simple...
grep -e <string> <files>
the for example: grep -e Daniel *.html
will show me in wich file the line WITH the string "Daniel" will appear. being more efficient, you can place another flag to show you the exact line number.
No need of cat, nor more to search on every file on a directory...haven't tryed yet on a full root search.
Hiope it helps.
On Wednesday 01 Feb 2006 23:00, Daniel Vogel wrote:
I had two suggestions:
- gnome-search-tool
- find ./ -name "*" -exec grep "string" {} /dev/null ;
Someone suggested even a better command solution than 2. above but I can't remember what it is. --
find . -type f -print0 |xargs -0 grep "string"
should work.
..err...my sugestion is much simple...
grep -e <string> <files>
the for example: grep -e Daniel *.html
will show me in wich file the line WITH the string "Daniel" will appear. being more efficient, you can place another flag to show you the exact line number.
No need of cat, nor more to search on every file on a directory...haven't tryed yet on a full root search.
Hiope it helps.
The problem is that, while this looks simple, I'm trying to find all config files that refer to my lan-name, and config files don't have a specific extension. In fact I can't think of any regular pattern to their names.
The problem with searches like Aaron's and Les' is that they pick up all the hundreds of email messages from both my current installation and the previous one, since I routinely mount an OldHome partition (one such search is still running). I could umount OldHome, but there's still going to be a lot of mail messages. Then there are hundreds more in the kde tmp files. Maybe I'm asking the impossible. I'll just have to back up and hope I find all the ones I need without too much delay.
Thanks to all for the suggestions.
Anne
On Thu, 2006-02-02 at 16:38 +0000, Anne Wilson wrote:
On Wednesday 01 Feb 2006 23:00, Daniel Vogel wrote:
I had two suggestions:
- gnome-search-tool
- find ./ -name "*" -exec grep "string" {} /dev/null ;
Someone suggested even a better command solution than 2. above but I can't remember what it is. --
find . -type f -print0 |xargs -0 grep "string"
should work.
..err...my sugestion is much simple...
grep -e <string> <files>
the for example: grep -e Daniel *.html
will show me in wich file the line WITH the string "Daniel" will appear. being more efficient, you can place another flag to show you the exact line number.
No need of cat, nor more to search on every file on a directory...haven't tryed yet on a full root search.
Hiope it helps.
The problem is that, while this looks simple, I'm trying to find all config files that refer to my lan-name, and config files don't have a specific extension. In fact I can't think of any regular pattern to their names.
To search ALL files, display the files with matching names AND the line that matches:
# find / -exec grep -iH pattern {} ;
Modify the find command to exclude directories you know you aren't interested in. For example to ignore any "mail" directories:
# find / -path "*mail*" -prune -o -exec grep -iH pattern {} ;
---------------------------------------------------------------------- - Rick Stevens, Senior Systems Engineer rstevens@vitalstream.com - - VitalStream, Inc. http://www.vitalstream.com - - - - There are only 10 kinds of people in the world -- those who - - understand binary and those who don't - ----------------------------------------------------------------------
On Thursday, Feb 2nd 2006 at 09:50 -0800, quoth Rick Stevens:
=>To search ALL files, display the files with matching names AND the line =>that matches: => => # find / -exec grep -iH pattern {} ; => =>Modify the find command to exclude directories you know you aren't =>interested in. For example to ignore any "mail" directories: => => # find / -path "*mail*" -prune -o -exec grep -iH pattern {} ;
GGAAAAAHH!
find dir -type f | xargs grep stuff
Learn it. Love it. The Bad Way will generate a child process to search one file. The Good Way will generate the minimal number of grep processes to do the job. Also note the use of -type f so you don't seaarch devices and directories.
Daniel Vogel wrote:
Give Les the prize:-)
I had two suggestions:
- gnome-search-tool
- find ./ -name "*" -exec grep "string" {} /dev/null ;
Someone suggested even a better command solution than 2. above but I can't remember what it is. --
find . -type f -print0 |xargs -0 grep "string"
This selects only files (not symlinks), and copes well wifh path names containing spaces and other difficult characters.
Here are two small improvements: find . -type f -print0 |xargs -0 --no-run-if-empty grep -H "string"
Otherwise, xargs may run grep with no filename args, and if grep has one filename arg it won't list the file name (the point of using /dev/null in some other examples).
Use of xargs reduces the number of times grep is loaded and run, sometimes an important matter.
should work.
..err...my sugestion is much simple...
grep -e <string> <files>
the for example: grep -e Daniel *.html
This doesn't descend subdirectories (the point of using -r).
Aa compatibility note. Probably not important to all, but I think recursion is fairly new (say. more recent than RHL 5.x or 6.x) - I don't remember seeing it before and I did look for it, and I'm sure I've asked about it. There may be other greps out there that don't support recursion (or -H for that matter).
akonstam@trinity.edu wrote: On Wed, Feb 01, 2006 at 04:22:07PM -0500, CodeHeads wrote:
On Wed, 2006-02-01 at 20:49 +0000, Anne Wilson wrote:
On Wednesday 01 Feb 2006 20:41, CodeHeads wrote:
How about this:
$du -a
| grep
This works well for me.
That returns files with the string in the name, I believe. I need files with the string in the body.
Anne
oooppss sorry Anne :) I was confused. LOL
I had two suggestions: 1. gnome-search-tool 2. find ./ -name "*" -exec grep "string" {} /dev/null ;
Someone suggested even a better command solution than 2. above but I can't remember what it is.
On Wed, 1 Feb 2006 16:42:19 +0000 Anne Wilson cannewilson@tiscali.co.uk wrote:
I need to list all files that refer to my network-name, but I can't work out a command to do it. I thought I would have to cat everything, piping through grep 'string', but that doesn't search recursively, the help-file doesn't show a recursive flag, and I'm not sure that it would actually give me the filenames anyway.
Help, please?
Anne
Registered Linux User No.293302 (http://counter.li.org/)
Anne,
find $startpoint -type f -exec grep -l $network-name {} ;
Change $startpoint to whatever place in the directory tree that you want to begin the search or cd to that place and use "." as the startpoint. Change $network-name to the string that you want to look for.
Dave
Anne Wilson wrote:
I need to list all files that refer to my network-name, but I can't work out a command to do it. I thought I would have to cat everything, piping through grep 'string', but that doesn't search recursively, the help-file doesn't show a recursive flag, and I'm not sure that it would actually give me the filenames anyway.
For a multitude of different ways of doing this, check out the thread from last month where the same question was asked:
http://www.redhat.com/archives/fedora-list/2006-January/msg02876.html
My personal favourite solution for this problem:
$ grep -i -r -l 'string' /place/to.start/searching
This would have been much easier to find in the archives if the OP from last month had used a sensible Subject: and hadn't hijacked another thread of course.
Paul.
Paul Howarth wrote:
Anne Wilson wrote:
I need to list all files that refer to my network-name, but I can't work out a command to do it. I thought I would have to cat everything, piping through grep 'string', but that doesn't search recursively, the help-file doesn't show a recursive flag, and I'm not sure that it would actually give me the filenames anyway.
For a multitude of different ways of doing this, check out the thread from last month where the same question was asked:
http://www.redhat.com/archives/fedora-list/2006-January/msg02876.html
My personal favourite solution for this problem:
$ grep -i -r -l 'string' /place/to.start/searching
This would have been much easier to find in the archives if the OP from last month had used a sensible Subject: and hadn't hijacked another thread of course.
That works well on files with spaces and other special characters just doesn't work well with links that aren't there. ;-) Thanks that fixed the spaces problem I was having and it found some broken links I didn't know I have (really need to run the FS tools).
Andy Green wrote:
Paul Howarth wrote:
$ grep -i -r -l 'string' /place/to.start/searching
Interesting gotcha with grep... doesn't look in files beginning with . when used like this.
Huh?
$ mkdir testdir $ echo This is a test > testdir/.testfile $ grep -i -r -l this testdir testdir/.testfile
Paul.
Paul Howarth wrote:
Andy Green wrote:
Paul Howarth wrote:
$ grep -i -r -l 'string' /place/to.start/searching
Interesting gotcha with grep... doesn't look in files beginning with . when used like this.
Huh?
$ mkdir testdir $ echo This is a test > testdir/.testfile $ grep -i -r -l this testdir testdir/.testfile
Methinks Andy is seeing the likes of
$ mkdir testdir $ echo This is a test > testdir/.testfile $ cd testdir $ grep -i -r -l this * grep: No match.
My favorite..
find . -print | xargs grep -i <string>
Slower, but in my experince, pretty bulletproof.
Paul wrote:
Interesting gotcha with grep... doesn't look in files beginning with . when used like this.
Huh?
$ mkdir testdir $ echo This is a test > testdir/.testfile $ grep -i -r -l this testdir testdir/.testfile
Methinks Andy is seeing the likes of
$ mkdir testdir $ echo This is a test > testdir/.testfile $ cd testdir $ grep -i -r -l this * grep: No match.
Yep youthinks right. The problem is in the glob expansion rather than grep then because the first recipe does find the .file for me too. Hm that makes a lot of sense because I noticed this when I saw grep was not descending into ~/.blah/ when given
cd ~ grep stuff * -R
of course
echo *
doesn't show .files either.
My favorite..
find . -print | xargs grep -i <string>
Slower, but in my experince, pretty bulletproof.
Time to retrain the old fingers :-)
-Andy
On Wed, 2006-02-01 at 19:12 +0000, Andy Green wrote:
Yep youthinks right. The problem is in the glob expansion rather than grep then because the first recipe does find the .file for me too. Hm that makes a lot of sense because I noticed this when I saw grep was not descending into ~/.blah/ when given
cd ~ grep stuff * -R
of course
echo *
doesn't show .files either.
See the "dotglob" option in the bash manpage.
My favorite..
find . -print | xargs grep -i <string>
Slower, but in my experince, pretty bulletproof.
Yep - this is my favourite also.
Cheers, Ben
On Wed, 2006-02-01 at 12:50, Paul wrote:
$ grep -i -r -l 'string' /place/to.start/searching
Interesting gotcha with grep... doesn't look in files beginning with . when used like this.
Huh?
$ mkdir testdir $ echo This is a test > testdir/.testfile $ grep -i -r -l this testdir testdir/.testfile
Methinks Andy is seeing the likes of
$ mkdir testdir $ echo This is a test > testdir/.testfile $ cd testdir $ grep -i -r -l this * grep: No match.
Errr, grep knows nothing about wildcard filename expansion. That is done by the shell before starting grep with the expanded list in its argument list. The shell does not expand filenames starting with . when you specify * as a wildcard. On the other hand, if you let grep recurse from the current directory like: grep -i -r -l this . it would find it.
-- Les Mikesell lesmikesell@gmail.com
On Wednesday 01 Feb 2006 16:58, Paul Howarth wrote:
My personal favourite solution for this problem:
$ grep -i -r -l 'string' /place/to.start/searching
That worked well when I searched /etc, but when I tried the same search on /usr or /var it got many 'no such file or directory' returns, and eventually reported a loop in the search. I wanted to save the results to a text file. The /etc one worked. The other two resulted in a text file being created, but at soon as it hit a non-existant file it jumped back to screen, and nothing at all is written in the text file.
Anne
On Wed, 2006-02-01 at 14:26, Anne Wilson wrote:
On Wednesday 01 Feb 2006 16:58, Paul Howarth wrote:
My personal favourite solution for this problem:
$ grep -i -r -l 'string' /place/to.start/searching
That worked well when I searched /etc, but when I tried the same search on /usr or /var it got many 'no such file or directory' returns, and eventually reported a loop in the search. I wanted to save the results to a text file. The /etc one worked. The other two resulted in a text file being created, but at soon as it hit a non-existant file it jumped back to screen, and nothing at all is written in the text file.
It's probably not a good idea to let things wander through /proc or /dev reading everything in sight. You might also have trouble with symlinks pointing to files that don't exist but I don't think that should make the program stop.