我有一个bash文件,它希望查找特定日期早于特定日期的文件并删除它们。它运行正常,我能够回显已删除文件的数量,但是当我尝试将整数变为变量时,我遇到了问题。
#!/bin/bash
# Make this dynamic to look at different directories.
pathtofolder=/var/www/website/temp2/
if [ $hours ]; then
# To specify older than one day it is better to talk in hours because
# the days integer is just an integer so everything less than 2 days
# would be 1 day, so 1 day 23 hours and 59 minutes is not greater than
# 1 day.
# For this reason I am using mmin and using the hours in minutes.
timeinmins=$(($hours*60))
elif [ $mins ]
then
timeinmins=$mins
else
# The default is 24 hours but we want to test with 24 minutes
timeinmins=24
fi
find "$pathtofolder"* -mmin +$timeinmins -exec rm -vr {} \; | output="$(wc -l)"
echo "Files deleted: $output"
echo "Minutes: $timeinmins"
在上述情况下,$output
为空白。
但是,这可以在下面工作,只是为了回应......
find "$pathtofolder"* -mmin +$timeinmins -exec rm -vr {} \; | "Files deleted: $(wc -l)"
有什么想法吗?提前谢谢。