Created
April 27, 2024 10:59
-
-
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
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
#!/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