lot_manager/bash/delete_than.sh

19 lines
403 B
Bash
Raw Normal View History

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