- 判断一个文件夹中的所有文件是否是最近5分钟内创建的
#!/bin/bash
folder_path="path/to/folder"
current_time=$(date +%s)
five_minutes_ago=$((current_time - 300))
if [ -d "$folder_path" ]; then
for file in "$folder_path"/*; do
if [ -f "$file" ]; then
file_creation_time=$(stat -c %Y "$file")
if [ "$file_creation_time" -ge "$five_minutes_ago" ]; then
echo "$file 是最近5分钟内创建的。"
else
echo "$file 不是最近5分钟内创建的。"
fi
fi
done
else
echo "文件夹不存在。"
fi
- 判断一个文件是否是最近5分钟内创建的
#!/bin/bash
file_path="path/to/xxx.jar"
current_time=$(date +%s)
five_minutes_ago=$((current_time - 300))
if [ -f "$file_path" ]; then
file_creation_time=$(stat -c %Y "$file_path")
if [ "$file_creation_time" -ge "$five_minutes_ago" ]; then
echo "文件是最近5分钟内创建的。"
else
echo "文件不是最近5分钟内创建的。"
fi
else
echo "文件不存在。"
fi
- 检查指定的文件夹是否在过去的5分钟内生成
#!/bin/bash
target_folder="/path/to/your/folder"
folder_creation_time=$(stat -c %Y "$target_folder")
current_time=$(date +%s)
time_difference=$((current_time - folder_creation_time))
five_minutes_in_seconds=300
if [ "$time_difference" -lt "$five_minutes_in_seconds" ]; then
echo "文件夹在过去的5分钟内生成。"
else
echo "文件夹不在过去的5分钟内生成。"
fi