Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 13 down vote accepted

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.

share|improve this answer
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. – Evan Teitelman Jan 1 '13 at 15:39
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? – l--''''''---------'''''''''''' Jan 1 '13 at 23:30
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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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