#!/bin/bash

input_dir=/path/to/input/dir

while true; do # Get list of files in input directory files=$(ls $input_dir)

# Loop through files
for file in $files; do
    # Get file creation time in seconds since epoch
    creation_time=$(stat -c %Y $input_dir/$file)

    # Get current time in seconds since epoch
    current_time=$(date +%s)

    # Calculate time difference in seconds
    time_difference=$((current_time - creation_time))

    # Check if time difference is greater than 1 hour (3600 seconds)
    if [ $time_difference -gt 3600 ]; then
        # Delete file
        rm $input_dir/$file
    fi
done

# Wait for 5 minutes before checking again
sleep 300

don

用shell写一个脚本监视一个输入目录删除出现超过一个小时的文件

原文地址: https://www.cveoy.top/t/topic/fnQp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录