shell遍曆檔案夾並執行命令

來源:互聯網
上載者:User

標籤:

背景:

有一個源碼包裡麵包含很多子目錄和makefile,打包後的壓縮包太大,需要將make產生的所有二進位檔案刪除然後再打包。

 

需求:

因此,要求在制定目錄的所有遞迴子目錄中執行make clean以清楚所有的目標檔案。

 

代碼:

寫了一段簡單的shell指令碼,有兩個功能:

1.遍曆所有子目錄,如果存在Makefile就執行make clean(當然也可以幹更多的事);

2.列出所有子目錄下大於10M(當然也可以指定其他值)的檔案。

 

話不多說上代碼:

#!/bin/bashrun_make(){        #如果該目錄下存在Makefile        if [ -f "Makefile" ];then            echo ""            echo ===================== FOUND ===================            pwd;            echo ===============================================            make clean;        fi}run_ls(){        pwd;        #列出大於10M的檔案        #ls -l |awk ‘{if($5 > 10485760){print $5}}‘        ls -l |awk ‘{if($5 > 10485760){print "--",$9,$5}}‘                echo ""}myfunc(){        cd $1;        #run_make;        run_ls;        for x in $(ls .)        do                if [ -d "$x" ];then                        myfunc $x;                        cd ..                fi                    done}p=.if [ $1 ];then    p=$1fiecho $pmyfunc $p

 

shell遍曆檔案夾並執行命令

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.