法1:rm -rf
1
2
3
4
5
6
|
#!/bin/bash
path=
/tmp
if
[ -e $path ]
#当/tmp不为空则执行
then
rm
-rf $path
fi
|
法2:find
1
2
3
4
5
|
#!/bin/bash
path=
/tmp
find
${path:-
/abc
} -
type
-f -name
"*.log"
-mtime +7|
xargs
rm
-f
#-mtime +7 删除7天以前的数据
|
1
2
|
${path:-
/abc
}
#如果path未定义,则表达式的值为/abc
|
本文转自 baishuchao 51CTO博客,原文链接:http://blog.51cto.com/baishuchao/1940214