Last active
July 6, 2020 22:31
-
-
Save mjambon/7868a4f706d6681b0d8a1e3cc757d055 to your computer and use it in GitHub Desktop.
Save all the previous copies of a config file without duplicates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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