del.sh
2016-03-04 00:58
274 查看
#!/bin/bash
echo "Program begins at `date`"
echo "Parameter number is : $#"
echo ""
if [ "$#" != 1 ] ; then
echo "ERROR: The parameter number input is wrong! Please check it!"
exit 1
fi
file_path=$1
file_num=0
if [ ! -d "$file_path" ] ; then
echo "ERROR: File Path does not exist!Please check it!"
exit 1
else
echo "File path is: ${file_path}"
echo ""
fi
#find_count:To canculate files numbers that you can find under the specified path
function find_count(){
if [ "$file_path" = "" ] || [ "$file_path" = "/" ] || [ "$file_path" = "/root" ] ; then
echo "ERROR: The path input is wrong! Please check it!"
exit 1
fi
#echo "file path is: ${file_path}"
file_count=`find ${file_path} -name "*.txt" -print |wc -l`
return $file_count
}
#delete the files if it exists
find_count
file_num=$?
if [ "$file_num" -gt 0 ] ; then
echo "$file_num files will be deleted"
#list the files you found
echo "File List:"
echo "#################################"
find ${file_path} -name "*.txt" -print
echo "#################################"
echo ""
#find ${file_path} -name "*.txt" -mtime +2 -exec rm -f {} \
else
echo "no file is found!"
exit 0
fi
echo "Program Run Successfully at `date` "
echo "Program begins at `date`"
echo "Parameter number is : $#"
echo ""
if [ "$#" != 1 ] ; then
echo "ERROR: The parameter number input is wrong! Please check it!"
exit 1
fi
file_path=$1
file_num=0
if [ ! -d "$file_path" ] ; then
echo "ERROR: File Path does not exist!Please check it!"
exit 1
else
echo "File path is: ${file_path}"
echo ""
fi
#find_count:To canculate files numbers that you can find under the specified path
function find_count(){
if [ "$file_path" = "" ] || [ "$file_path" = "/" ] || [ "$file_path" = "/root" ] ; then
echo "ERROR: The path input is wrong! Please check it!"
exit 1
fi
#echo "file path is: ${file_path}"
file_count=`find ${file_path} -name "*.txt" -print |wc -l`
return $file_count
}
#delete the files if it exists
find_count
file_num=$?
if [ "$file_num" -gt 0 ] ; then
echo "$file_num files will be deleted"
#list the files you found
echo "File List:"
echo "#################################"
find ${file_path} -name "*.txt" -print
echo "#################################"
echo ""
#find ${file_path} -name "*.txt" -mtime +2 -exec rm -f {} \
else
echo "no file is found!"
exit 0
fi
echo "Program Run Successfully at `date` "
相关文章推荐
- 学习软件设计模式的书籍
- Web Api如何传递POST请求
- Tomcat 环境搭建
- 正则表达式验证
- raft协议的go语言实现
- Ubuntu配置连接android手机
- JAVA网站高并发解决方案
- caffe之(二)pooling层
- [C++11]_[初级]_[weak_ptr的使用场景]
- ScrollView的滚动监听
- [C++11]_[初级]_[weak_ptr的使用场景]
- 【学习笔记】day2数据存储和界面展现第一天 11_api获取外部存储的真实路径 12_检查外部存储状态
- 数据库表转换成javaBean对象小工具
- [FAQ07421] 待机时,怎么看AP每次wake up起来的时长
- [FAQ09541] [Power]待机电流问题,如何查找EINT唤醒源
- [FAQ09542] [Power]待机电流问题,如何查找wakelock
- [FAQ08317] android apk 的root 权限和USB adb 权限的区别
- [FAQ03042] 如何编译MTK的模拟器
- 小组级git服务器搭建
- Git使用参考