I want to quickly create a backup of a file, by creating a duplicate with a '~' at the end, in terminal. Is there any straight forward single command way of doing this?


Create a shell function

backup() {
   cp ${1} ${1}~

Put it in your shell rc file, for bash it is ~/.bashrc. Source .bashrc or start a new shell.

 . ~/.bashrc
 backup youFile

And you have a copy of yourFile.

  • Thanks, that works great. But out of curiosity, what exactly is the . ~/.bashrc line doing? – Henry Gibson Jan 1 '13 at 14:08
  • Henry: That sources your .bashrc file in your home directory; it's short form for source ~/.bashrc. Doing this will allow you to use the backup() function added to the file. – user97589 Jan 1 '13 at 15:39
  • 1
    Clarification: The . ~/.bashrc is needed only the once, because it is executed automatically every time you open a terminal. – Paddy Landau Jan 1 '13 at 16:42
  • whats the difference between this and just copying a file? – Alex Gordon Jan 1 '13 at 23:30
  • 1
    Nothing really, you only need to type in 1 argument instead of 2. – McNisse Jan 2 '13 at 0:53

Rsync works Great for backup. It is mostly used for server backup.

rsync -avP <source> <destination>

Here You can defines source and destination. source may be file or directly on local or Remote server/machine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.