Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Created April 27, 2024 10:59
Show Gist options
  • Save Konfekt/8fc2c096cd69ffb836e18ac6927273dc to your computer and use it in GitHub Desktop.
Save Konfekt/8fc2c096cd69ffb836e18ac6927273dc to your computer and use it in GitHub Desktop.
backup a file or restore it if it ends in a bkp extension
#!/usr/bin/env bash
# for each file, either back it up or restore it, in case it ends in a bkp extension
for f in "$@"; do
p="${f%/}"
[ "$p" != "${p%.bkp}" ] &&
cp --archive --interactive --update --verbose "$p" "${p%.bkp}" ||
cp -aiuv "${p}" "$p.bkp"
done; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment