BREAKING NEWS

2012/06/11

How to Backup of a file from the Command line on Mac OS X



It’s always a good idea to backup a file if you’re going to be making some changes to it and you’re uncertain of the outcome. In the Finder this is as simple as just selecting the file and hitting Command+D to create a duplicate of the file in question, but in the command line you typically have to use the cp command, point it at the file, and then specify the copied version. Here’s a nice variation of that to make fast backups of any file through the Terminal:

cp file.txt{,.backup}                                                                                         

Notice there are no spaces between the end of the first file and the brackets. This creates copy of “file.txt” with the added extension “.backup”, resulting in “file.txt.backup”.

Whether or not this is faster for you than typing “cp file1 file2″ is going to depend on your keyboarding abilities and how much you use tab completion, but regardless of which approach you take it’s good to be in the habit of making backups so you can quickly restore things to how they were before being edited, be it htaccess, /etc/hosts, or just a plist file. 

Share this:

Post a Comment

 
Copyright © 2014 Deepersolids. Designed by OddThemes