# Create reference file with the date of today 00:00:00.000000 am
# as our upper date limit (excluded bound)
# that's equal to all yesterday up to 11:59:59.999999 pm
touch -d 'today' /tmp/before.tmp # before today is yesterday
# Create reference file with the date of 150 days ago as our lower date limit
# that's equal to 150 days ago 00:00:00.000000 am
touch -d '150 days ago' /tmp/after.tmp
# Find and delete files
find \
"$directory" \
-maxdepth 1 \
-type f \
-size 0 \
-anewer /tmp/after.tmp \
-not -anewer /tmp/before.tmp \
-regex '.*/.*\.\(txt\|xml\|csv\|mrc\)' \
-delete
1条答案
按热度按时间9w11ddsr1#
设备故障
find
命令:"$directory"
:从变量开始在此路径中查找$directory
-maxdepth 1
:限制搜索到此目录而不降序子目录-type f
:搜索实际文件(没有目录,没有链接…)-size 0
:搜索实际大小为0的文件-anewer /tmp/after.tmp
:搜索比此引用文件的日期最近访问的文件/tmp/after.tmp
-not -anewer /tmp/before.tmp
:以及最多或在引用文件日期之前访问的/tmp/before.tmp
-regex '.*/.*\.\(txt\|xml\|csv\|mrc\)'
:搜索其全名和路径与posix正则表达式“/..(txt| xml| csv| mrc)”匹配的文件-delete
:删除找到的与前面所有选项 predicate 匹配的文件