[comp.unix.questions] Directory searching utility

ahmad@icsib6.Berkeley.EDU (Subutai Ahmad) (08/09/89)

Does anyone have a utility which searches the current directory
and all its subdirectories for files which match the arguments?
For example (if it was named lsd), the command
	lsd *.c *.h
would list all the .c and .h files in the current subtree.  It should
indicate which directories each file came from.

ls -R * | egrep ".*\.[ch]"  almost works. It lists the files but 
not their associated directories.

--

Subutai Ahmad
ahmad@icsi.berkeley.edu

limes@sun.com (Greg Limes) (08/09/89)

In article <16137@pasteur.Berkeley.EDU> ahmad@icsib6.Berkeley.EDU (Subutai Ahmad) writes:

>  Does anyone have a utility which searches the current directory
>  and all its subdirectories for files which match the arguments?
>  For example (if it was named lsd), the command
>	   lsd *.c *.h
>  would list all the .c and .h files in the current subtree.  It should
>  indicate which directories each file came from.

Could be written, but at a minimum you would have to quote those
pesky stars to get them past your shell.

Why not just use find?

	% find . -name '*.[hc]' -print
--
-- Greg Limes	limes@sun.com	...!sun!limes	73327,2473	[choose one]

ahmad@icsib6.Berkeley.EDU (Subutai Ahmad) (08/10/89)

du -a | grep '\.[hc]' also works.


#! /bin/sh

# lsd:  search the current directory and all its subdirectories
#       for files which match the arguments.
#

PATH=/bin:/usr/bin

case $* in
        "")     echo "Usage: lsd 'pattern' ..." 1>&2; exit 1 ;;
        -*)     opt="$opt $1" ; shift ;;
esac

for p in $*
do
        case $n in
                "")     n="-name $p" ;;
                *)      n="$n -o -name $p" ;;
        esac
done

find . \( $n \) -exec ls $opt {} \;

--

Subutai Ahmad

jba@harald.ruc.dk (Jan B. Andersen) (08/10/89)

ahmad@icsib6.Berkeley.EDU (Subutai Ahmad) writes:

># lsd:  search the current directory and all its subdirectories
>#       for files which match the arguments.
>#

>--

>Subutai Ahmad

Nice script- he just forgot to tell who wrote it :-(
---
Jan B. Andersen, Datalogi 19.1     .---------------------------.       /^^^\
Roskilde Universitetscenter       ( "SIMULA does it with CLASS" )     { o_o }
Postbox 260,                       `---------------------------'  <--- \ o /
DK-4000  Roskilde (Denmark)       IfUmust: +45 46 75 77 11            -mm--mm-

iwarner@zaphod.axion.bt.co.uk (Ivan Warner,G44 SSTF,6632,) (08/10/89)

From article <16137@pasteur.Berkeley.EDU!, by ahmad@icsib6.Berkeley.EDU (Subutai Ahmad):
! Does anyone have a utility which searches the current directory
! and all its subdirectories for files which match the arguments?
! For example (if it was named lsd), the command
! 	lsd *.c *.h
! would list all the .c and .h files in the current subtree.  It should
! indicate which directories each file came from.
! 
! ls -R * | egrep ".*\.[ch]"  almost works. It lists the files but 
! not their associated directories.
! 

	find . -name "*.[ch]" -print

news@pcsbst.UUCP (news) (08/22/89)

	Try:
		find . -name "*.[ch]" -print
    
    Torsten.
---
Name    : Torsten Homeyer
Company : PCS GmbH, Pfaelzer-Wald-Str. 36, 8000 Munich W-Germany.
UUCP    : ..[pyramid ;uunet!unido]!pcsbst!tho  (PYRAMID PREFERRED!!)
DOMAIN  : tho@pcsbst.pcs.[ COM From rest of world; DE From Europe ]