avatar

目录
Script CodeClean

Script-CodeClean

磁盘代码清理脚本工具

说明

  • 删除代码目录下的build文件夹以及out开头的文件夹,对于磁盘代码清理特别有效。

  • 由于一些特殊项目原因,需要排除package,cmd目录,以免误删,具体源码可以自定义修改

  • 本脚本只使用linux,window环境可用git-bash环境或者ubuntu-bash运行

使用

shell
1
2
chmod +x codeClean.sh
./cleanCode.sh codeDir

参数 codeDir 待清理的目录路径,绝对路径

示例

shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 laird@192  ~/Work/00doc/study/Script/codeClean  tree testDir
testDir
├── build
│   └── test.sh
├── cmd
│   └── test.sh
├── out
│   └── test.sh
├── package
│   └── test.sh
└── subdir
├── build
│   └── test.sh
└── out
└── test.sh

7 directories, 6 files

清理文件夹

shell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
laird@192  ~/Work/00doc/study/Script/codeClean  chmod +x codeClean.sh
laird@192  ~/Work/00doc/study/Script/codeClean  ./codeClean.sh /Users/laird/Work/00doc/study/Script/codeClean/testDir
################################################################
##########################dir clean start######################
################################################################
----------------------------------
-----foud clear dir, rm it!------
/Users/laird/Work/00doc/study/Script/codeClean/testDir/build
----------------------------------
-----foud cmd dir , no need to traverse!------
/Users/laird/Work/00doc/study/Script/codeClean/testDir/cmd
----------------------------------
-----foud clear dir, rm it!------
/Users/laird/Work/00doc/study/Script/codeClean/testDir/out
----------------------------------
-----foud package dir , no need to traverse!------
/Users/laird/Work/00doc/study/Script/codeClean/testDir/package
----------------------------------
-----foud clear dir, rm it!------
/Users/laird/Work/00doc/study/Script/codeClean/testDir/subdir/build
----------------------------------
----------------------------------
-----foud clear dir, rm it!------
/Users/laird/Work/00doc/study/Script/codeClean/testDir/subdir/out
----------------------------------
################################################################
##########################dir clean finish######################
################################################################
laird@192  ~/Work/00doc/study/Script/codeClean  tree testDir
testDir
├── cmd
│   └── test.sh
├── package
│   └── test.sh
└── subdir

3 directories, 2 files
laird@192  ~/Work/00doc/st

源码

sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash

function clearDir(){
echo "----------------------------------"
echo "-----foud clear dir, rm it!------"
echo $1
rm -rf $1
echo "----------------------------------"
}

function cleanCode(){
# echo "start clean dir $1"
targetDir=`ls $1`
for fileName in $targetDir
do
if [ -d $1"/"$fileName ]
then
#echo $1"/"$fileName
# delete build dir
if [ ${fileName} = 'build' ] || [ ${fileName:0:3} = "out" ];
then
clearDir $1"/"$fileName
# exclude package or cmd dir
elif [ ${fileName} = 'package' ] || [ ${fileName} = "cmd" ];
then
echo "-----foud ${fileName} dir , no need to traverse!------"
echo $1"/"$fileName
else
# Traverse dir
cleanCode $1"/"$fileName
fi
else
#echo $fileName
if [[ ${fileName} = 'settings.gradle' ]];
then
echo "-----foud as project dir ------"
echo $1
#gradleClean $1 ${fileName}
fi
fi
done
}

echo "################################################################"
echo "##########################dir clean start######################"
echo "################################################################"
cleanCode $1
echo "################################################################"
echo "##########################dir clean finish######################"
echo "################################################################"
文章作者: laird.li
文章链接: https://lairdli.top/2020/05/10/Script-CodeClean/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 黎明鸟飞去

评论