This small script realizes the routine task of finding and archiving files older than a given date from a directory structure.
#!/bin/bash if [ ! -d "$2" ]; then echo "usage: $0 <timestamp> <directory>" exit 0 fi ts="$1" dir="$2" tmpdir=`mktemp -d` trap "rm -rf '$tmpdir'" exit touch -d "$ts" "$tmpdir/tsfile" || exit echo "+ finding files older than $ts in $dir" find "$dir" -type f -not -cnewer "$tmpdir/tsfile" > "$tmpdir/filelist" archive="archive-$ts-"`date +%s`".tgz" echo "+ packing contents to $archive" tar -czf "$archive" --files-from "$tmpdir/filelist" && { echo "+ removing files" ; cat "$tmpdir/filelist" | xargs -n1 rm -f ;} echo "+ done"