Subdirectory listing

Ray E. Saddler III ray3rd at ssc-vax.UUCP
Tue May 23 08:37:00 AEST 1989


In article <215 at cs.columbia.edu>, olasov at cs.columbia.edu (Benjamin Olasov) asks:
> 
> I'm interested in finding a unix command usage that will return the complete
> path names of all subdirectories below a given directory, so that, given a
> directory tree like this:
> 
> 				( Example deleted )
> 
> the command would take the directory of interest as its argument, as in:
> 
> $ mycommand /files/home/users
> 
> and return the subdirectories in the format:
> 
> /files/home/users/user1
> /files/home/users/user2
> /files/home/users/user2/data
> /files/home/users/user2/data/bin
> /files/home/users/user3
> /files/home/users/user3/docs
> /files/home/users/user4
> /files/home/users/user5
> /files/home/users/user6
> /files/home/users/user6/mail
> /files/home/users/user6/hacks
> 
> What's the easiest way to do this?
> 

Give this script a spin around the block:

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

#!/bin/sh
#
	if [ $# = 0 ]
	then 
	  echo "Usage: mycommand <dir>"
	  #
	  # You could ask for the directory here, or assume a
	  # default, if you so desired...I opt to exit non-zero
	  #
	  exit 1
        else
	  for I in $*
	  do
	    find $I -type d -exec ls -d {} \;
          done
        fi
        exit 0

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Sample usages:

$ mycommand
Usage: mycommand <dir>
$
$ mycommand /user4/ray3rd /user4/law /user4/jsk /user4/markb
/user4/ray3rd
/user4/ray3rd/SYTEK
/user4/ray3rd/HUMOR
/user4/ray3rd/bin
/user4/ray3rd/clock
/user4/ray3rd/VTREE
/user4/ray3rd/3B1
/user4/ray3rd/block
/user4/ray3rd/CADSA
/user4/ray3rd/UUMAP
/user4/ray3rd/shartest
/user4/ray3rd/STANDARDS
/user4/law
/user4/jsk
/user4/markb
$
$ mycommand .
.
./SYTEK
./HUMOR
./bin
./clock
./VTREE
./3B1
./block
./CADSA
./UUMAP
./shartest
./STANDARDS
$
-- 
Ray E. Saddler III       |    __  __ __       __ |          UseNet
Boeing Aerospace         |   / / / //   //| //   | uw-beaver!ssc-vax!ray3rd
P.O. Box 3999 m.s. 3R-05 |  /-< / //-  // |// _  |         PhoneNet
Seattle, Wa.  98124  USA | /__//_//__ //  //__/  |      1+206-657-2824



More information about the Comp.unix.wizards mailing list