Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to do the following: when a file is changed then the old file should be backed up to another location with different name on Linux. E.g. whenever example.text is changed, at each change, new files should be created like this: example1.text, example2.text ...

share|improve this question
    
Other than doing it yourself (renaming files as you are saving) or having some sort of regular backup system (like TimeMachine for MacOS)(or say every 5 minutes) I don't think AFAIK a system is that aware of files to do that itself. The answer might depend on what program you are using. –  Doktoro Reichard Aug 23 '13 at 9:37
    
As far as i know you can't have this functionality natively. You can either use version control (git) or there might be filesystems with this functionality ? –  Kwaio Aug 23 '13 at 9:37

2 Answers 2

There are three good methods to do this:

  1. If you use a GUI text editor such as gedit/pluma and enable the option Create a backup copy of files before saving in the preferences then your example1.txt is saved to example1.txt~ upon save. You can enable this for nano with nano -B example1.txt. Additionally cp with cp -b example1.txt example2.txt will create example1.txt~ as well.

  2. Use a cron job to backup files in a directory regularly, you can even combine this with a VCS. I can include the script I use if you ask nicely.

  3. Use a VCS directly such as git and commit your files on a local repository (you can even migrate it to a remote location later if you choose) anytime you alter them.

It's possible you are simply asking for a log rotater, in which case you can use the command logrotate with details here and here

share|improve this answer
1  
OP hasn't specified much but as far as gedit goes, I use a plugin called "doublesave" that timestamps backups. I wrote about it in How to enable Gedit autosave files with name of current system Date and Time. –  user151227 Aug 23 '13 at 11:49

Assuming using ZFS is an option (available either through FUSE or natively on Linux), one way would be to use ZFS automatic snapshots to achieve something close to what you want.

Older snapshots are destroyed so you would need some tuning if you really want to keep each and every file update.

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.