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 ...

  • 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 ? – mveroone Aug 23 '13 at 9:37

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


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.

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.