zoukankan      html  css  js  c++  java
  • shell命令tree

    在Windwows下很喜欢tree命令,在CenntOS下也有这条命令,在网上找到了源代码和一段简单的脚本,

    完整的tree源代码可以在这里下载: ftp://mama.indstate.edu/linux/tree/

    简易的tree脚本如下:

    #!/bin/sh
    #######################################################
    #  UNIX TREE                                          #
    #  Version: 2.3                                       #
    #  File: ~/apps/tree/tree.sh                          #
    #                                                     #
    #  Displays Structure of Directory Hierarchy          #
    #  -------------------------------------------------  #
    #  This tiny script uses "ls", "grep", and "sed"      #
    #  in a single command to show the nesting of         #
    #  sub-directories.  The setup command for PATH       #
    #  works with the Bash shell (the Mac OS X default).  #
    #                                                     #
    #  Setup:                                             #
    #     $ cd ~/apps/tree                                #
    #     $ chmod u+x tree.sh                             #
    #     $ ln -s ~/apps/tree/tree.sh ~/bin/tree          #
    #     $ echo "PATH=~/bin:\${PATH}" >> ~/.profile      #
    #                                                     #
    #  Usage:                                             #
    #     $ tree [directory]                              #
    #                                                     #
    #  Examples:                                          #
    #     $ tree                                          #
    #     $ tree /etc/opt                                 #
    #     $ tree ..                                       #
    #                                                     #
    #  Public Domain Software -- Free to Use as You Like  #
    #  http://www.centerkey.com/tree  -  By Dem Pilafian  #
    #######################################################
    
    echo
    if [ "$1" != "" ]  #if parameter exists, use as base folder
       then cd "$1"
       fi
    pwd
    ls -R | grep ":$" |   \
       sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
    # 1st sed: remove colons
    # 2nd sed: replace higher level folder names with dashes
    # 3rd sed: indent graph three spaces
    # 4th sed: replace first dash with a vertical bar
    if [ `ls -F -1 | grep "/" | wc -l` = 0 ]   # check if no folders
       then echo "   -> no sub-directories"
       fi
    echo
    exit

  • 相关阅读:
    MSBuild、条件编译、预处理命令
    批量数据插入SqlBulkCopy
    WPF 双向绑定
    编程思想之一
    python 提交表单
    python 添加用户
    python 分页
    day9 IO多路复用
    day9 线程、进程和协程深入版
    day8 进程、线程 简介版
  • 原文地址:https://www.cnblogs.com/java20130726/p/3218684.html
Copyright © 2011-2022 走看看