Operating System - HP-UX
1834142 Members
2406 Online
110064 Solutions
New Discussion

Searching all files in a directory

 
SOLVED
Go to solution
fg_1
Trusted Contributor

Searching all files in a directory

All

I need to figure out the quickest way to search an entire directory (/etc/lp/interface/model.orig) searching each and every file for which printers listed here have Banner="yes" as part of their file.

Can someone provide me a quick and dirty search command to do this?

Thanks all.
9 REPLIES 9
Sachin Patel
Honored Contributor

Re: Searching all files in a directory

Hi Frank

#cat * |grep -i banner |grep yes

Works for me. I don't know this is the best way or not.

Sachin
Is photography a hobby or another way to spend $
Helen French
Honored Contributor
Solution

Re: Searching all files in a directory

Hi,

Try this:

# cd /etc/lp/interface/model.orig
# find . -depth -exec grep -l 'Banner=yes' {} \;

This will list you the name of the file which have the specific pattern.

HTH,
Shiju
Life is a promise, fulfill it!
harry d brown jr
Honored Contributor

Re: Searching all files in a directory


find /etc/lp/interface/model.orig -type f -exec grep -l "Banner=\"yes\"" {} \;

live free or die
harry
Live Free or Die
fg_1
Trusted Contributor

Re: Searching all files in a directory

Shiju & Harry

What is the purpose of the {}\ and putting the \yes\ with the \ in the command?
H.Merijn Brand (procura
Honored Contributor

Re: Searching all files in a directory

use GNU grep

# grep -r -a 'Banner="yes"' /etc/lp/interface/model.orig
Enjoy, Have FUN! H.Merijn
pap
Respected Contributor

Re: Searching all files in a directory

Hi,
You can do following :

1. cd /etc/lp/interface/model.orig

2. enter following command

grep \banner\=\"yes\" *

It will serve your purpose.

Thanks,
-Piyush.
"Winners don't do different things , they do things differently"
SHABU KHAN
Trusted Contributor

Re: Searching all files in a directory

Frank,

You could do this:
This will search recursively through all files in all subdirectories and will print the files which has that string on stdout.

The key here is /dev/null, this will list the files before the match.

find -name "*" -exec grep "Banner=yes" /dev/null {} \;

The following will only grep text files (this way you don't get junk character on the screen as a result of grepping binaries)

grep "Banner=yes" `find -name "*" -exec file {} \; | grep text | awk -F: '{print $1}`

Hope this helps !

-Shabu


Helen French
Honored Contributor

Re: Searching all files in a directory

Hi Frank,

Check the man pages of 'find' command. That will give you an explanation.

syntax is: -exec cmd

{} and \; should be used along with -exec option. {} replaces any command arguments by the current path. The end of cmd must be punctuated by a semicolon (;).

The other \" tells the command to consider " as a normal character.

HTH,
Shiju
Life is a promise, fulfill it!
fg_1
Trusted Contributor

Re: Searching all files in a directory

Thanks all Problem was resolved. All of your responses were helpful. Enjoy the points thnx for the knowledge.

FG.