[feature] remove files with name older than N days
This commit is contained in:
parent
c4415a89fa
commit
5a41e35968
20
devops/bin/rm-ndays-ago.sh
Executable file
20
devops/bin/rm-ndays-ago.sh
Executable file
|
@ -0,0 +1,20 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$#" -lt 2 ] ;then
|
||||
echo "Remove files/directories which name contains DatePart and before n days ago"
|
||||
echo
|
||||
echo " Usage $0 <dir> <days>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TARGET_DIR=${1%/}
|
||||
THRES_DATE=$(date -d "$2 days ago" +%Y%m%d)
|
||||
|
||||
for entry in $(ls "$TARGET_DIR") ;do
|
||||
DATE=$(echo "$entry" | grep -oP '\b(\d{8})\b')
|
||||
if [ -n "DATE" ] && [ "$DATE" -lt "$THRES_DATE" ] ;then
|
||||
rm -f $TARGET_DIR/$entry
|
||||
fi
|
||||
done
|
Loading…
Reference in New Issue
Block a user