lot_manager/bash/delete_than.sh

19 lines
413 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-08 14:57:36 +08:00
size=$(du -sh "$folder" | awk '{print int($1/1024)}')
2023-12-07 16:25:01 +08:00
while [[ $size -gt 20 ]]
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-08 14:57:36 +08:00
size=$(du -sh "$folder" | awk '{print int($1/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