Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ames!haven!decuac!e2big.mko.dec.com!bacchus.pa.dec.com!decwrl!apple!amdahl!fai!georgeb From: georgeb@fai.UUCP (George Bosworth) Newsgroups: comp.sources.wanted Subject: Unix "Tree" Command Wanted Message-ID: <2906@fai.UUCP> Date: 10 Aug 90 17:40:49 GMT Reply-To: georgeb@fai.com (George Bosworth) Distribution: usa Organization: Fujitsu America, Inc Lines: 60 In article <2899.UUCP> I asked for a UNIX version of the DOS "tree" command. Many responders didn't know, or had forgot, that the DOS "tree" command produces an INDENTED subdirectory tabulation, wherein each deeper level of subdirectory is indented further to the right, to give instant visualization of the hierarchy. The frequently-suggested UNIX commands *find*, *ls -R*, and *du* produce only columnar ouput. Several responders sent C programs or shell scripts that did some flavor of indented hierarchal directory tabulation, or offered or pointed to programs or scripts, including lengthy C programs available by UUCP as uunet!/usr/spool/ftp/comp.sources.misc/volume9/dtree.Z and uunet!/usr/spool/ftp/comp.sources.unix/volume15/vtree.Z. One respnder sent a uvtree2 Bourne shell script that was published by Ray Swartz in the June 1989 Unix Review. It worked well. Following this up, I saw a dtree Bourne shell script published by Ray in the October issue. It works well and is extremely compact: : # @(#) dtree -- Visual display of directory trees # Author: Unknown USAGE="Usage: $0 [starting-directory-name]" case $# in 0) startdir="." ;; #If no param, start at dot 1) if [ ! -d $1 ]; then #Single param; directory? echo "\"$1\" not a directory." >&2 echo $USAGE >&2 exit 1 fi startdir=$1 ;; #Use single param as start *) echo $USAGE >&2 #Multiple params exit 2 ;; esac (cd $startdir; pwd) #In subshell, print start name find $startdir -type d -print | sort -f | #Find, sort names sed -e "s,^$startdir,," \ -e "/^$/d" \ -e "s,[^/]*/\([^/]*\)$,\|----\1," \ -e "s,[^/]*/,| ,g" Here is a sample run: pwd /fai/ddd/georgeb dtree /fai/ddd/georgeb |----Keep |----News |----Present | |----Big | | |----Filed | | |----Working | |----Small |----Pthread |----Recruit |----Uunet George Bosworth georgeb@fai.com Fujitsu America Inc. uunet!fai.com!georgeb