Skip to content

Instantly share code, notes, and snippets.

@kanasite
Last active April 11, 2023 01:34
Show Gist options
  • Save kanasite/2a90cbd419d5426a8ee313ffa43431c4 to your computer and use it in GitHub Desktop.
Save kanasite/2a90cbd419d5426a8ee313ffa43431c4 to your computer and use it in GitHub Desktop.
Remove Old plots by Interval
#!/bin/bash
## USAGE
## ./remove_plots.sh /PATH/TO/DIRECTORY/ 2021-07-01 30m
## first argument is path, must be end with trailing "/"
## second argument is target date, meaning plots that created after this date WILL NOT BE DELETED, if you specify 2021-07-01, only filename containing 2021-06-30 or before wil be deleted.
## third argument is the interval, adjust yourself according to your plotting speed or how soon you want to trigger next deletion.
SOURCE_DIR=$1
TARGET_DATE=${2:-"2021-07-01"}
INTERVAL=${3:-"30m"}
ARR=()
if [ -n "$1" ]; then
for entry in "$SOURCE_DIR"*
do
FILE_NAME=$(basename "$entry")
FILE_DATE=${FILE_NAME:9:10}
[[ $FILE_DATE < $TARGET_DATE ]] && ARR+=($entry)
done
echo "${#ARR[@]} plots to be removed:"
printf '%s\n' "${ARR[@]}"
for v in "${ARR[@]}"
do
echo "Sleeping for $INTERVAL..." && sleep $INTERVAL
echo "Removing $v" && rm $v
done
else
echo "first argument must be specified manually."
fi
@kanasite
Copy link
Author

Hi @benjfranklin100 , by default the sorting of the files in directory are alphabetically ordered, hence if u're using the default plot file name which will contain datetime, the oldest file in the directory will be get picked first.

This is just a simple bash (mainly used 1-off during the Chia plot format upgrade), u can clone it into multiple directories if u have multiple plotters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment