Skip to content

Instantly share code, notes, and snippets.

@v6
Created September 22, 2016 20:54
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 v6/f8257bf027a0ef54163031a15345a5e3 to your computer and use it in GitHub Desktop.
Save v6/f8257bf027a0ef54163031a15345a5e3 to your computer and use it in GitHub Desktop.
// , This has some super neato functions you can use as aliases elsewhere.
# Nathan's Backup function.
# It's best to create backup files by moving the original file aside to its new name with mv and the ncopying it back to its original name.
# cp -p preserves original file's set attributes.
# mv and cp -p preserve the original file's settings like the time it was created and modified.
# Also, be advised, processes might have an open reference to the original file. This process will not cause them errors. Be aware of this, if you are expecting errors from those files.
# This defines a backup bash function bakmvcp that timestamps a new file name and does the switch for you.
function bakmvcp () {
newname=$1.`date +%Y%m%d.%H%M.bak`;
mv $1 $newname;
echo "Backed up $1 to $newname.";
cp -p $newname $1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment