hierarchive (597B)
1 #!/bin/bash 2 3 # TODO: make sure that $2 is not a relative path / not a subfolder! 4 set -e 5 6 # https://stackoverflow.com/a/246128 7 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" 8 cd "$DIR" 9 10 # move old files from $1 to $2 11 # expected usage: download/upload folder of a web browser, scratch folder, etc. 12 13 NDAYS="7" 14 15 D=$(date '+%Y-%m-%d') 16 F="$2/$D" 17 #mkdir "$F" 18 cd "$1" 19 # find all old files and move them away 20 find -type f -mtime +$NDAYS -print0 | xargs -r -0 -n 1 "$DIR/hierarchive_file" "$F" 21 22 # now, recursively remove all empty directories 23 find . -type d | xargs rmdir -p 2>/dev/null 24