linux命令定时查找并删除指定目录php文件
作用:php只该出现在该出现的目录,某些不该出现的目录是不能出现的!哈哈,所以这个代码就有用了
#!/bin/bash
# 设置需要检查的目录
directory="/www/wwwroot/xxxxx/upload"
# 查找所有 php 文件,并处理
find "$directory" -type f -name "*.php" | while read -r file; do
# 获取文件的创建时间
create_time=$(stat --format='%W' "$file")
# 如果文件创建时间无法获取(例如文件系统不支持),则使用最后修改时间
if [ "$create_time" -eq 0 ]; then
create_time=$(stat --format='%y' "$file")
fi
# 格式化时间,只保留日期和时间部分
create_time=$(echo "$create_time" | cut -d ' ' -f 1,2)
# 删除文件
rm "$file"
# 输出删除信息
echo "成功删除文件: $file, 创建时间: $create_time"
done