From 5dc5ab7e4cae584bcbba56a637c8f6fc8e6b32e8 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 7 Jan 2024 02:33:13 +0200 Subject: [PATCH] Added a cleanup script for testing --- cleanup-files.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 cleanup-files.sh diff --git a/cleanup-files.sh b/cleanup-files.sh new file mode 100755 index 0000000..9fb2e99 --- /dev/null +++ b/cleanup-files.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +LIMIT=30 +DIR="$1" + +if [ -z "${DIR}" ] +then + echo "The directory value cannot be empty" + exit 1 +fi + +NO="0" +NUMBER=$(find ${DIR} -maxdepth 1 -type f |wc -l) + +echo "The number of files in the directry: ${NUMBER}" +if [[ $NUMBER -gt $LIMIT ]] #if number greater than limit +then + del=$(($NUMBER-$LIMIT)) + if [ "$del" -lt "$NO" ] + then + del=$(($del*-1)) + fi + + echo $del + + FILES=$(find ${DIR} -maxdepth 1 -type f -printf "%T@ %f\n" | sort | cut -d' ' -f2 | tail -n "$del") + + echo "${FILES}" +fi