Last active
February 14, 2019 04:45
-
-
Save alhoo/3dfb0dc415242e93b16eabe2826d9e6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
N=30 | |
DRYRUN=false | |
WORKDIR=/home/lasse/Desktop | |
HISTORY=__HISTORY | |
HISTORY_DIR=$WORKDIR/$HISTORY/$(date +%Y%m%d) | |
if [ "$1" != "" ]; then N=$1; fi | |
mkdir -p $(dirname $HISTORY_DIR) | |
find $WORKDIR -maxdepth 1 -mmin +$(($N*24*60)) -not -name $HISTORY -print0 > $HISTORY_DIR.txt | |
#find $WORKDIR -maxdepth 1 -mmin +$(($N*24*60)) -type f -not -name $HISTORY | |
if [ $(cat $HISTORY_DIR.txt|tr '\0' '\n'|wc -l) -gt 0 ]; then | |
if $DRYRUN; then | |
cat $HISTORY_DIR.txt|xargs -0 echo mv -t $HISTORY_DIR | |
else | |
mkdir -p $HISTORY_DIR | |
echo "Moving the following to $HISTORY_DIR:" | |
cat $HISTORY_DIR.txt|tr '\0' '\n'|sed 's/^/ /' | |
# Move older than N days work to history | |
cat $HISTORY_DIR.txt|xargs -0 mv -t $HISTORY_DIR | |
fi | |
fi | |
rm $HISTORY_DIR.txt | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment