下面的短小的shell程序可以列出目录树, 充分利用了sed强大的模式匹配能力.
目录树形式如下:
.
`----shellp
`----updates
`----wu-ftpd-2.4
| `----doc
| | `----examples
| `----src
| | `----config
| | `----makefiles
| `----support
| | `----makefiles
| | `----man
| `----util
摘自<>
#!/bin/sh
# dtree: Usage: dtree [any directory]
dir=${1:-.}
(cd $dir; pwd)
find $dir -type d -print | sort -f | sed -e "s,^$1,," -e "/^$/d"
-e \
"s,[^/]*/\([^/]*\)$,\`----\1," -e "s,[^/]*/,|
,g"
--
※ 来源:.饮水思源 bbs.sjtu.edu.cn.[FROM: ms.fudan.edu.cn]
本文转自中文Linux论坛