返回列表 发帖

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

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

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

TOP

script.sh
#!/bin/bash
find "/path" -type f -mtime +10 -deleteCOPY
crontab
0 23 * * * script.shCOPY

TOP

回复 2# qixiaobin0715


    好的

TOP

回复 3# newswan


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

TOP

回复 3# newswan


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

TOP

本帖最后由 newswan 于 2024-8-16 20:12 编辑
#!/bin/bash
time_target="2300"
time_current=$(date +%H%M)
timestamp_current=$(date +%s)
if [[ $time_current -gt $time_target ]]; then
timestamp_target=$(date -d "tomorrow 23:00:00" +%s)
else
timestamp_target=$(date -d "today 23:00:00" +%s)
fi
wait_seconds=$((timestamp_target - timestamp_current))
echo "wait:$wait_seconds 秒"
sleep $wait_seconds
echo "23:00"
find "/path" -type f -mtime +10 -deleteCOPY

TOP

回复 5# 占卜家

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

TOP

返回列表