The shell traverses the folder and executes the command

Source: Internet
Author: User

Background:

There is a source package that contains many subdirectories and makefile, and the packed package is too large to be deleted and then packaged by all the binaries created by make.

Demand:

Therefore, make clean is required to clear all the target files in all the recursive subdirectories of the catalog.

Code:

Wrote a simple shell script with two features:

1. Traverse all subdirectories and execute make clean if there is makefile (more can be done, of course);

2. list files in all subdirectories that are larger than 10M (and of course you can specify other values).

Words not much to say on the code:

#!/bin/Bashrun_make () {#如果该目录下存在Makefileif[-F"Makefile"]; Then            Echo ""            Echo===================== FOUND ===================pwd; Echo=============================================== MakeClean ; fi}run_ls () {pwd; #列出大于10M的文件 #ls-L |awk '{if ($ > 10485760) {print $}}'        ls-L |awk '{if ($ > 10485760) {print "--", $9,$5}}'                Echo ""}myfunc () {CD $1;        #run_make;        Run_ls;  forXinch$(ls .)  Do                if[-D"$x"]; ThenMyFunc $x;                Cd.. fi                     Done}p=.if[ $1]; ThenP=$1fiEcho$pmyfunc $p

The shell traverses the folder and executes the command

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.