打印本文 打印本文 关闭窗口 关闭窗口
linux 列出目录树
作者:武汉SEO闵涛  文章来源:敏韬网  点击数1006  更新时间:2009/4/22 20:48:18  文章录入:mintao  责任编辑:mintao
 

列出目录树

技巧管理员(2000-12-22 23:53)

〖返回〗〖转发〗

下面的短小的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"

打印本文 打印本文 关闭窗口 关闭窗口