Discussion:
[9fans] Is there a Plan 9 equivalent of the find command
(too old to reply)
Kim Shrier
2007-06-10 19:33:38 UTC
Permalink
This is probably me just stuck in the UNIX mind set again. I have
looked through the commands and I don't see anything that does what
find does. What I am trying to do is look in a directory that has
many files and subdirectories and find any file that contains a string.
In UNIX, I would do something like this.

find . -type f -exec grep some_pattern {} \; -print

What is the Plan 9 way?

Thanks,
Kim
Kris Maglione
2007-06-10 19:44:40 UTC
Permalink
Post by Kim Shrier
This is probably me just stuck in the UNIX mind set again. I have
looked through the commands and I don't see anything that does what
find does. What I am trying to do is look in a directory that has
many files and subdirectories and find any file that contains a string.
In UNIX, I would do something like this.
find . -type f -exec grep some_pattern {} \; -print
What is the Plan 9 way?
Thanks,
Kim
http://plan9.bell-labs.com/wiki/plan9/FAQ/index.html#INSTALLATION_AND_ADMINISTRATION

http://plan9.bell-labs.com/wiki/plan9/UNIX_to_Plan_9_command_translation/index.html
--
Kris Maglione

A little humility is arrogance.
erik quanstrom
2007-06-10 19:46:37 UTC
Permalink
there is a find in /n/sources/contrib/quanstro/find.tbz but it
does not have the options you show. they way it is generally
used is

find . | grep pattern

Du(1) may also serve the same function, but it seems a bit clunkier
to me.

- erik
Kris Maglione
2007-06-10 20:11:30 UTC
Permalink
Post by erik quanstrom
find . | grep pattern
There are tens of scripts in contrib which do that with du.

But the request was for something more like:

grep some_pattern */*

or

grep some_pattern `{find .}

or

find . | read -m |
ifs='
' while(l=`{sed 10q}) {
grep -n some_pattern $l
}

-- find --
#!/bin/rc

du -a | sed 's/[^ ]* //'

-- xarg --
#!/bin/rc
rfork s

n=10
if(~ $1 -l) {
n = $2
shift 2
}

{read -m; echo -n 'interrupted' >/proc/$pid/notepg} |
while() {
ifs='
' { l = `{sed $n^q } }
$* $l
}

-- --

find . | xarg grep -n some_pattern
--
Kris Maglione

Roses are red violets are blue
I am schizophrenic and so am I
Federico Benavento
2007-06-11 18:10:04 UTC
Permalink
I use russ' lsr, so lsr | grep pattern

http://swtch.com/lsr.c
--
Federico G. Benavento
Dan Cross
2007-06-17 07:28:47 UTC
Permalink
Back in the day, I wrote two commands: walk and sor. Walk was
somewhat similar to Russ's lsr command (these days, lsr would probably
be better; the only additional thing walk offered was the ability to
limit the depth of searching via an option). Sor took other commands
as arguments; for each filename that it read (presumably generated by
walk), it would apply each test successively; if one returned `true'
it would print out the resulting filename. (sor, incidentally, stands
for `stream or').

The idea behind find, when you step back a little bit, is to produce
some list of files (or otherwise do something interesting with them)
after applying a set of predicates to them. The predicates can be
strung together into aribrary sequences that form filters based on the
boolean value of evaluating the predicates for each file that find
visits. Well, in Plan 9, we form filters that reduce lists using
pipes, and sor was just a convenient way to compute the boolean or of
a bunch of predicate evaluations. It worked out, I thought,
reasonably well, but never made it into the distribution; I guess no
one else saw the point. But, if you search through the 9fans
archives, you can probably find the tools (and they're in my contrib
directory on sources). I still thing it's mostly an improvement.

- Dan C.
Post by Kim Shrier
This is probably me just stuck in the UNIX mind set again. I have
looked through the commands and I don't see anything that does what
find does. What I am trying to do is look in a directory that has
many files and subdirectories and find any file that contains a string.
In UNIX, I would do something like this.
find . -type f -exec grep some_pattern {} \; -print
What is the Plan 9 way?
Thanks,
Kim
Continue reading on narkive:
Loading...