SHELL定时清理文件

 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 //查看定时任务日志

crontab操作

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值