mybin

my ~/bin
git clone https://a3nm.net/git/mybin/
Log | Files | Refs | README

hierarchive (529B)


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