Skip to content

Instantly share code, notes, and snippets.

@Iruyan-Zak
Created August 10, 2016 13:18
Show Gist options
  • Save Iruyan-Zak/993f573cffc271e3b84b36685e3d4dfc to your computer and use it in GitHub Desktop.
Save Iruyan-Zak/993f573cffc271e3b84b36685e3d4dfc to your computer and use it in GitHub Desktop.
#! /bin/bash
# usage watch -n<sec> backup <filename>
set -eu
: $1
dir=$1.backup
mkdir -p $dir
touch $dir/00_00_00_00_00_$1
cat $1 && diff -Nb $1 $(ls $dir/*_$1 | tail -n1) >/dev/null || cp $1 $dir/$(date +%m_%d_%H_%M_%S)_$1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment