说明
此脚本用于清除特定目录下的文件,不删除子目录。
dir_list表示目录列表,temp_dir表示临时目录。
1. 如果dir存在,且不为空,则删除该目录下所有文件(不删除子目录);
2. 再判断是否存在临时目录,当临时目录不为空时:
如果脚本执行时带all参数,删除整个临时目录中的文件;
否则仅删除临时目录中的文件,保留文件夹;
脚本:
#!/bin/bash # clean some direcotrys dir_list=( # # output $HOME/data/rf_???/ok directories such as: /app/billapp/data/rf_001/ok、/app/billapp/data/rf_002/ok $HOME/data/rf_???/err # # kpi $HOME/log/kpi_publisher/kpi $BILL_LOG1/kpi_publisher # # log $BILL_LOG1/chf/chf_??? directories such as: $BILL_LOG1/chf/chf_001、$BILL_LOG1/chf/chf_002 ) # tmp_top temp_dir="/tmp_top" decode_dir=( # ) if [ -n "$1" ] && [ "$1" = "decode" ] then dir_list=(${decode_dir[@]}) fi # echo date date for dir in ${dir_list[@]} do # if dir exists and is not empty, then clean it if [ -d $dir ] && [ "`ls -A $dir`" != "" ] then # remove files echo "find $dir -maxdepth 1 -type f -exec rm {} \;" find $dir -maxdepth 1 -type f -exec rm {
} \; # if tmp_dir exists and is not empty, then clean it if [ -d $dir$temp_dir ] && [ "`ls -A $dir$temp_dir`" != "" ] then # suport option if [ -n "$1" ] && [ "$1" = "all" ] then echo "rm -rf $dir$temp_dir" rm -rf $dir$temp_dir echo continue fi echo "find $dir$temp_dir -type f -exec rm {} \;" find $dir$temp_dir -type f -exec rm {
} \; fi echo fi done exit 0
讯享网

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/39989.html