Added a cleanup script for testing
This commit is contained in:
parent
06e41dbd30
commit
5dc5ab7e4c
29
cleanup-files.sh
Executable file
29
cleanup-files.sh
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user