[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] 求助Linux shell脚本定时删除10天以上未修改过的文件

一个Linux shell脚本,目标是实现:每天晚上11点删除   某个目录的里面的超过10天以上未修改过的文件,请问大佬们该怎么写呢

标题最好不要这样没头没脑,关注的人会少很多,你会失去快速解决问题的机会。

TOP

script.sh
  1. #!/bin/bash
  2. find "/path" -type f -mtime +10 -delete
复制代码
crontab
  1. 0 23 * * * script.sh
复制代码

TOP

回复 2# qixiaobin0715


    好的

TOP

回复 3# newswan


    感谢,这个代码能在集中器里运行吗

TOP

回复 3# newswan


    不用crontab的话该如何实现功能呢

TOP

本帖最后由 newswan 于 2024-8-16 20:12 编辑
  1. #!/bin/bash
  2. time_target="2300"
  3. time_current=$(date +%H%M)
  4. timestamp_current=$(date +%s)
  5. if [[ $time_current -gt $time_target ]]; then
  6. timestamp_target=$(date -d "tomorrow 23:00:00" +%s)
  7. else
  8. timestamp_target=$(date -d "today 23:00:00" +%s)
  9. fi
  10. wait_seconds=$((timestamp_target - timestamp_current))
  11. echo "wait:$wait_seconds 秒"
  12. sleep $wait_seconds
  13. echo "23:00"
  14. find "/path" -type f -mtime +10 -delete
复制代码

TOP

回复 5# 占卜家

集中器 是什么?
bash一般都能运行

TOP

返回列表