Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

2 Answers 2

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. –  paraxor 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? –  Yuck 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.

share|improve this answer

Your Answer

 
discard

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.