[shell] Delete the files and folders before the status of the specified file changes

reference document

Linux finds files required by a specified time

script example

#!/bin/bash

# 删除指定时间之前文件,单位:分钟
ago=75

# 监控路径,必须使用使用绝对路径,防止意外删除重要文件
monitoring_path="/home/dev/test/test"
# 使用find命令查找75分钟前状态未变更的文件,并将其删除
find $monitoring_path -type f -cmin +$ago | xargs rm -rf;
# 使用find命令查找75分钟前的空文件夹,并将其删除
find $monitoring_path -type d -cmin +$ago  | xargs rm -rf;

Guess you like

Origin blog.csdn.net/macaiyun0629/article/details/132158273