Tree命令的简单应用

2010-11-21 05:47

这个脚本用于生成脚本所在目录下所有文件和文件夹索引的,是我平时用来备份软件索引的小程序~
具体代码如下:

#!/bin/bash
#project by iCyOMiK

cd `dirname $0` && echo "NOW THE PATH IS: "`pwd`

function going2exit
{
until [ $DaoShu -lt 1 ]; do
    if [ "$DaoShu" -eq 1 ]; then
        units="second  !!"
    else
        units="seconds !!"
    fi
    echo "The TreeApp Will Closing In $DaoShu $units"
    DaoShu=$(($DaoShu - 1))
    sleep $JianGe
done
exit $exitcode
}

sudo -v
    TREE=`which tree`
    if [ -z "$TREE" ]; then
        echo "The program will install tree immediately !"
        echo
        sudo apt-get install tree
        TREE=`which tree` && if [ -z "$TREE" ]; then exitcode=1; echo "can't find tree"; going2exit; fi
    fi
    echo
    echo --- 'delete tree file' ---
    sudo chattr -i "tree.s" && sudo rm -v "tree.s"
    sudo chattr -i "tree.v" && sudo rm -v "tree.v"
    echo
    echo --- 'create tree file' ---
    echo Creating \'tree.s\'
    EXCLUDE="EXCLUDE1|EXCLUDE2"
    sudo tree -adlN  -I "$EXCLUDE" >"tree.s" && sudo chmod 444 "tree.s" && sudo chattr -i "tree.s"
    echo Creating \'tree.v\'
    sudo tree -aFiNf -I "$EXCLUDE" >"tree.v" && sudo chmod 444 "tree.v" && sudo chattr -i "tree.v"
sudo -k
echo
echo ------------------------------------------
JianGe=1
DaoShu=3
exitcode=0
going2exit

原文链接: http://blog.jtwo.me/the-simple-application-of-tree-command