add: rm expired file shell script
This commit is contained in:
16
misc/rmexpfiles.sh
Normal file
16
misc/rmexpfiles.sh
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# rm expired file with filename like *20231028111213.zip"
|
||||||
|
|
||||||
|
filepath=$1
|
||||||
|
duration=$2
|
||||||
|
|
||||||
|
find $filepath -maxdepth 1 -type f -name "*[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*" -printf "%f\n" | while read filename; do
|
||||||
|
datestr=$(echo "$filename" | grep -oE '[0-9]{8}')
|
||||||
|
filedate=$(date -d "$datestr" +%s)
|
||||||
|
sevendaysago=$(date -d "$duration days ago' +%s)
|
||||||
|
if [ "$filedate" -lt "$sevendaysago" ]; then
|
||||||
|
rm -f "$filepath/$filename"
|
||||||
|
echo "rm file: $filename"
|
||||||
|
fi
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user