find /root -mtime +7 -type f -iname "*.log*" | xargs rm -rf
本条命令的含义
- 查找/root目录下所有7天前创建的文件类型为文件且文件名匹配*.log*的文件
- 强制删除1(以上)所找到的所有文件
- -atime : 按文件访问时间来查找文件,-n指n天以内,+n指n天以前
- -ctime : 按文件创建时间来查找文件,-n指n天以内,+n指n天以前
- -mtime : 按文件更改时间来查找文件,-n指n天以内,+n指n天以前
- -amin : 同 -atime (单位:分钟)
- -cmin : 同 -ctime (单位:分钟)
- -mmin : 同 -mtime (单位:分钟)
-type b/d/c/p/l/f : 查是块设备、目录、字符设备、管道、符号链接、普通文件
- -iname : 名字匹配忽略大小写
- -name : 名字匹配区分大小写
- /bin/systemctl start crond.service //启动服务
- /bin/systemctl stop crond.service //关闭服务
- /bin/systemctl restart crond.service //重启服务
- /bin/systemctl reload crond.service //重新载入配置
- crontab -e //编辑crontab文件
- crontab -r //删除crontab文件
- crontab -l //列出crontab文件
- tail -f /var/log/cron //查看定时任务日志