Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mjambon
Last active July 6, 2020 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjambon/7868a4f706d6681b0d8a1e3cc757d055 to your computer and use it in GitHub Desktop.
Save mjambon/7868a4f706d6681b0d8a1e3cc757d055 to your computer and use it in GitHub Desktop.
Save all the previous copies of a config file without duplicates
# Bash function
#
# Usage: save foo.bar
# - creates a file like foo.bar.d41d8cd,
# - overwrites previous copy if identical,
# - preserves other previous versions with very high probability
#
save() {
file=$1
if [[ -f "$file" ]]; then
hash=$(md5sum "$file" | cut -c1-7)
cp "$file" "$file"."$hash"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment