lot_manager/bash/delete_than.sh

18 lines
387 B
Bash
Raw Normal View History

2023-12-05 18:20:19 +08:00
#!/bin/bash
set -e
# 指定文件夹路径
folder="/home/pi/mp4"
# 获取文件夹的大小
size=$(du -sh "$folder" | awk '{print int($1/1024/1024)}')
2023-12-07 16:25:01 +08:00
while [[ $size -gt 20 ]]
2023-12-05 18:20:19 +08:00
do
# 获取最早创建的文件
oldest_file=$(ls -tr | head -1 | xargs)
rm -f $oldest_file
size=$(du -sh "$folder" | awk '{print int($1/1024/1024)}')
2023-12-07 16:25:01 +08:00
if [[ $size -le 20 ]]
2023-12-05 18:20:19 +08:00
then
exit 0
fi
done