删除临时目录
# find /tmp -atime +7 -type f -print
# find /tmp -atime +7 -type f -exec rm -f {} \;
# find /tmp -type d -empty -exec rmdir {} \;
清理用户目录
Example 9.1. 示例文件
#!/bin/bash
TMPDIR=~/tmp
WARNTIME=30
RMTIME=60
SIZE="500k"
USERS='awk -F: '{if ($3 >= 500) print $1}' /etc/passwd'
# Find files to warn about
for user in $USERS ; do
homedir='eval echo ~$user'
find $homedir -atime +$WARNTIME -type f -size $SIZE -print \
> $TMPDIR/$user
[ -s "$TMPDIR/$user" ] && {
# Some files were found
mail -s 'SCHEDULED FOR DELETION!!' "$user" < "$TMPDIR/$user"
}
rm -f "$TMPDIR/$user"
done
# Now, delete any files that are old enough
find $homedir -atime +$RMTIME -type f -size $SIZE -exec rm -f {} \;
tmpwatch
# tmpwatch 168 /tmp //删除/tmp目录下一周(168小时)未访问的文件
cfengine