找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 11990|回复: 7

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

[复制链接]
发表于 2024-8-14 11:17:51 | 显示全部楼层 |阅读模式
一个Linux shell脚本,目标是实现:每天晚上11点删除   某个目录的里面的超过10天以上未修改过的文件,请问大佬们该怎么写呢
发表于 2024-8-14 11:45:01 | 显示全部楼层
标题最好不要这样没头没脑,关注的人会少很多,你会失去快速解决问题的机会。
发表于 2024-8-14 13:35:32 | 显示全部楼层
script.sh
  1. #!/bin/bash
  2. find "/path" -type f -mtime +10 -delete
复制代码
crontab
  1. 0 23 * * * script.sh
复制代码
 楼主| 发表于 2024-8-14 13:47:36 | 显示全部楼层
回复 2# qixiaobin0715


    好的
 楼主| 发表于 2024-8-14 13:49:08 | 显示全部楼层
回复 3# newswan


    感谢,这个代码能在集中器里运行吗
 楼主| 发表于 2024-8-14 15:05:54 | 显示全部楼层
回复 3# newswan


    不用crontab的话该如何实现功能呢
发表于 2024-8-16 20:05:22 | 显示全部楼层
本帖最后由 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
复制代码
发表于 2024-8-16 20:05:50 | 显示全部楼层
回复 5# 占卜家

集中器 是什么?
bash一般都能运行
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-16 20:57 , Processed in 0.017836 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表