Last active
September 29, 2022 11:34
-
-
Save Khazbs/d84f8771967ac4f4d22f0fcd98500442 to your computer and use it in GitHub Desktop.
Add this to your .bashrc to get a handy bak function for backing up files and directories
This file contains hidden or 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
# Create backup copies of files or directories | |
bak() { | |
local name="$1.bak" | |
if [ -e "$name" ]; then | |
local -i num=2 | |
while [ -e "$name$num" ]; do | |
num+=1 | |
done | |
cp -rv "$1" "$name$num" | |
else | |
cp -rv "$1" "$name" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As always, don't forget to re-login or
source .bashrc
after adding.Usage example: