delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/09/11:25:27

Date: Sun, 9 Mar 1997 18:10:20 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: sysdev AT mb DOT sympatico DOT ca
cc: djgpp AT delorie DOT com
Subject: Re: Search DOS hard drive question
In-Reply-To: <199703072306.SAA08843@delorie.com>
Message-ID: <Pine.SUN.3.91.970309180916.26812V-100000@is>
MIME-Version: 1.0

On Fri, 7 Mar 1997, DJ Delorie wrote:

> > I want to search all files on the hard 
> > drive for a specific character string; 
> > in the root directory, and all subdirectories.
> > ALL files.  
> 
> If you have a version of grep built with DJGPP Version 2
> (v2gnu/grep20b.zip), the answer is *really* simple:
> 
> 	grep "mystring" .../*

This will work, but has two drawbacks:

	1) It prints an error message about every directory it
encounters.

	2) If you happen to have a binary file which includes
"mystring", the ``line'' printed to the screen can garble the entire
screen.

Therefore, I suggest using the following command instead:

   find / ! -type d -exec grep -q "mystring" {} ; -print

The `-q' switch caused `grep' to only report whether the file contains
the string via its exit status, rather than printing the line with
that string.

If you want to exclude executable programs, say this:

   find / ! -type d -exec ! -perm 0755 grep -q "mystring" {} ; -print

`find' is part of GNU Findutils (v2gnu/find41b.zip).

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019