-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclearFiles.sh
More file actions
executable file
·73 lines (54 loc) · 1.22 KB
/
clearFiles.sh
File metadata and controls
executable file
·73 lines (54 loc) · 1.22 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#/bin/bash/
# Title : clear bad files (cdf)
# Date : Sat Apr 11 19:05:12 CST 2015
# Author: andychen (bootoo@sina.cn)
storePath='/home/andy/backup/badFiles/'
mkdir -p $storePath
pwd=`pwd`
pwd=${pwd/\//from_}
# 检查输入(不可以有两级路径)
check(){
num=`echo ${1} | awk -F/ '{print NF}'`
if [ $num -gt 2 ]; then
if [ $num -gt 2 ]; then
return 0
fi
num=`echo ${1} | awk -F./ '{print NF}'`
if [ $num -ne 2 ]; then
return 0
fi
fi
return 1
}
for file in $@; do
check ${file}
res=$?
if [ ${res} != 1 ]; then
echo '+-------------------------- +'
echo '| input error |'
echo '+-------------------------- +'
exit 0
fi
cd ${storePath}
mkdir -p './'${pwd}
cd - >> /dev/null
here=${storePath}${pwd}
fName=${file/.\//}
fName=${fName/\//}
# 检查同名文件是否已经存在
if [ -e ${here}/${fName} ]; then
cd ${here}
order=0
lss=(`ls | grep "^\${fName}[0-9]"`)
if [ ${lss} ]; then
num=${#lss[@]}
last=${lss[${num} - 1]}
last=${last/${fName}/}
order=$(( ${last} + 1 ))
fi
cd - >> /dev/null
mv -f ${file} ${here}/${fName}${order}
else
mv -f ${file} ${here}
fi
done