[Herts] re: Top Tips

Ian Gregory yahoo at zenatode.org.uk
Wed Feb 18 19:18:01 GMT 2004


On Wed, Feb 18, 2004 at 06:24:18PM +0000, Neil Youngman wrote:
> On Wednesday 18 Feb 2004 12:21 am, Mr. Spock wrote:
> > On Tue, Feb 17, 2004 at 12:59:20AM +0000, Ian Gregory wrote:
> > > In a previous email Mr Spock suggested we post top tips for
> > > working with the dreaded (to those coming from Windoze anyway)
> > > command line, well here are a couple:
> > >
> > > 1)
> > > Say you want to find all files in /etc (or any subdirectory of
> > > /etc) that have a .foo extension and have been modified in the
> > > last 3 days. Well, "find" is your friend:
> > >
> > > find /etc -type f -name \*.foo -mtime 3
> >
> > Excellent. I knew there must be a way of finding files within
> > directories like grep looks through a single file. Maybe grep
> > can be persuaded to use wildcards to scan a directory (tree);
> > I'll have to read up on that.
> 
> Wildcards are normally interpreted by the shell, so need to be quoted.

Or escaped in some other way, which is why I used \*.foo instead
of simply *.foo

> it sounds as though you are looking for something like
> 
> find /path/to/dir \( -name '*.jsp' -o -name '*.java' ) -print | xargs grep RE
> 
> to search some directories for the regexp RE in JSP or java source files. The 
> -print can be omitted on linux, but I keep it in for portability.

Or use exec, as in
find /path/to/dir -name \*.jsp -exec grep -H RE {} \;

(I think the -H option to grep will force printing of the filename in
which the match was found)

I know that xargs is useful but it is not something I have used as
yet - time to learn about it I think!

Ian Gregory



More information about the Herts mailing list