Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!lll-crg!ames!aurora!jaw From: jaw@aurora.UUCP (James A. Woods) Newsgroups: comp.sources.d Subject: "one-line" tinkertoy tree display Message-ID: <574@aurora.UUCP> Date: Mon, 8-Dec-86 19:02:32 EST Article-I.D.: aurora.574 Posted: Mon Dec 8 19:02:32 1986 Date-Received: Mon, 8-Dec-86 23:52:59 EST Organization: NASA Ames Research Center, Mt. View, Ca. Lines: 38 Try this incredibly fiendish script on a directory name: echo $1; find $1 -type d -print | tr / \\1 | sort -f | tr \\1 / |\ sed -e s,\^$1,, -e /\^$/d -e "s,[^/]*/\\([^/]*\\)\$, \`-----\\1," -e "s,[^/]*/, | ,g" Thanks and a tip o' the hat to Doug Kerr of NASA Ames Research Center (ames!doug). Attached see the spoiler explanation from USENET of 1984. ----- >From postnews Tue Dec 11 21:57:08 1984 Subject: directory tree display made simple Newsgroups: net.unix,net.wanted.sources # George of the Jungle quote goes here. Someone asked about tree printing. For the sub-problem of displaying UNIX directory trees, there's always the one-liner (courtesy Doug Kerr of Sterling Software Corp.) echo $1; find $1 -type d -print | tr / \\1 | sort -f | tr \\1 / |\ sed -e s,\^$1,, -e /\^$/d -e "s,[^/]*/, ,g" This just does directories -- if you want all files, take out the "-type d". Explanation: it works by substituting tabs for pathname slashes (the invisible literal tab occurs before the ",g" above); the translits bracketing the sort helps alphabetize '/' before [a-zA-Z]. And if you remember that other punctuation can replace the slash in ed/sed syntax (as the comma does in the script), you needn't say "Deadhead Ed had edited it" fifty times fast. I find that anything which prints directory trees "vertically" is likely to be complicated enough to have bugs, as well as being too screen-dependent. It will take some CPU time on big directory structures, but if one runs the Ames Fast File Finder [ed. note -- a slow version of this appears in BSD 4.3], it can be made near-instantaneous, though that's another story ... -- James A. Woods (ames!jaw)