shell指令碼執行個體

來源:互聯網
上載者:User

shell指令碼執行個體 1、切換工作目錄至位置參數給出的目錄,依次向這些目錄中的每個檔案或子目錄問好,統計這些目錄下的各種檔案及子目錄個數,並顯示。 01#! /bin/sh02 03#切換工作目錄至位置參數給出的目錄04#依次向這些目錄中的每個檔案或子目錄問好05#統計這些目錄下的各種檔案及子目錄個數,並顯示06 07if [ $# -lt 1 ]08then09    echo "parameter's number error!";10    exit 1;11fi;12 13while [ $# -gt 0 ]14do15    if [ -f $1 ]16    then17        echo "$1 is not a dir!";18    else  19        cd $120 21        bfiles=0;  #塊裝置檔案22        cfiles=0;  #字元裝置檔案23        pfiles=0;  #管道檔案24        lfiles=0;  #連結檔案/目錄25        sfiles=0;  #sock檔案26        files=0;   #普通檔案27        dirs=0;    #目錄檔案28        total=0;   #總檔案數29        for var in `ls $1`30        do31            total=`expr $total + 1`;32            echo "hello $var";33            if [ -b $var ]34            then35                bfiles=`expr $bfiles + 1`; 36            elif [ -c $var ]37            then38                cfiles=`expr $cfiles + 1`;39            elif [ -S $var ]40            then41                sfiles=`expr $sfiles + 1`;42            elif [ -p $var ]43            then44                pfiles=`expr $pfiles + 1`;45            elif [ -h $var ]46            then47                lfiles=`expr $lfiles + 1`;48            elif [ -f $var ]49            then50                files=`expr $files + 1`;51            elif [ -d $var ]52            then53                dirs=`expr $dirs + 1`;54            fi;55        done56      57        echo "the number of bfiles is $bfiles";58        echo "the number of cfiles is $cfiles";59        echo "the number of lfiles is $lfiles";60        echo "the number of sfiles is $sfiles";61        echo "the number of pfiles is $pfiles";62        echo "the number of files is $files";63        echo "the number of dirs is $dirs";64        echo "total file number  is $total";65    fi;66    echo "************************************"67    shift;68done

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.