From d1dee12232d820deb18b0fe582e6f5a1d230eaa5 Mon Sep 17 00:00:00 2001 From: xyj <10908227994@qq.com> Date: Tue, 5 Dec 2023 18:20:19 +0800 Subject: [PATCH] update --- cron_delete_mp4.sh | 8 ++++++++ delete_than.sh | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 cron_delete_mp4.sh create mode 100644 delete_than.sh diff --git a/cron_delete_mp4.sh b/cron_delete_mp4.sh new file mode 100644 index 0000000..1a04e16 --- /dev/null +++ b/cron_delete_mp4.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# 设置文件保留时间为2天 +DAYS=2 + +# 使用find命令查找所有符合条件的文件 +find /home/pi/mp4 -type f -mtime +$DAYS -exec rm -f {} \; + diff --git a/delete_than.sh b/delete_than.sh new file mode 100644 index 0000000..8a8c1c9 --- /dev/null +++ b/delete_than.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -e +# 指定文件夹路径 +folder="/home/pi/mp4" + +# 获取文件夹的大小 +size=$(du -sh "$folder" | awk '{print int($1/1024/1024)}') +while [[ $size -gt 22 ]] +do + # 获取最早创建的文件 + oldest_file=$(ls -tr | head -1 | xargs) + rm -f $oldest_file + size=$(du -sh "$folder" | awk '{print int($1/1024/1024)}') + if [[ $size -le 22 ]] + then + exit 0 + fi +done \ No newline at end of file