Gedit and medit are two text editors that I know of that allow me to save a backup. So, if I create a file called temp.txt the next time I edit it and then save it, I'll have a backup called temp.txt~.

My question is this: is there a text editor that allows me to have backups named in a serial fashion so that I can have more than just the one backup in case I want to go back to the file as it existed a few revisions ago? For example, I'd have temp.txt as the latest version and temp.bak.1, temp.bak.2, etc.?

If that is not possible, is there some script that will automatically rename a backup each time it is created so that serial versions are retained? Even a temp.timestamp.txt would be great.

(I don't mind a solution using nano as the text editor.)

I should clarify that I'm not a coder or programmer. I just want to have previous versions of text files that I edit. These text files maybe .css or .rc or .svg files that form part of a theme. So if I edit some aspect of a theme's file, I can go back a bit in case I don't like a change I made.

  • 1
    Maybe it would be better to use any VCS? Also you can write simple script based on sleep/at/cron/etc (or even inotify) which will do a lot of copies. Also you can configure syslogd to do this. – Eddy_Em Apr 1 '13 at 7:13
  • Could you please expand "VCS"? – user15760 Apr 1 '13 at 7:14
  • VCS - version control system (like mercurial, git and so on). But I think, syslogd really can help you. – Eddy_Em Apr 1 '13 at 7:15
  • I should have made clear I'm quite new to all this and don't know scripting but I'll take a look and see if I can figure out how to do so. – user15760 Apr 1 '13 at 7:17
  • 1
    You don't need to know everything: hg init, hg add, hg commit and hg revert are possibly enough. If you have it installed already, you can type hg help command to find the help that you need. – Bernhard Apr 1 '13 at 8:13

There is a simple way to use mercurial for version control. First install it.

To configure mercurial make a file ~/.hgrc with next content:

username = Your name <your mail>
verbose = True

If you use some mercurial servers, you can add more info to this file (read man hgrc).

After that cd to directory with your text files. For example:

> cd /tmp
> mkdir data && cd data
> cat > text_file.txt
Hello, this is a file.

You can add also any number of files. After we must init mercurial:

> hg init

By default there's no files still, so we must to say mercurial, that we want to include all:

> hg st
? text_file.txt
> hg add    
adding text_file.txt
> hg st
A text_file.txt

Now we make do simple commit:

> hg comm -m 'first run'
committed changeset 0:87e90c949984

Now do some fixes and see difference:

> cat >> text_file.txt 
Add one line.
> hg diff
diff -r 87e90c949984 text_file.txt
--- a/text_file.txt Mon Apr 01 12:52:14 2013 +0400
+++ b/text_file.txt Mon Apr 01 12:53:47 2013 +0400
@@ -1,1 +1,2 @@
 Hello, this is a file.
+Add one line.

Now make another commit, after watch hg log: you will see both commits.

To return to first commit just do so:

> hg upd -r 0:87e90c949984
resolving manifests
getting text_file.txt
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
> cat text_file.txt 
Hello, this is a file.

You see: a file is old.

Now restore last file:

> hg upd                  
resolving manifests
getting text_file.txt
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
> cat text_file.txt 
Hello, this is a file.
Add one line.

Also you may do a simple script:

while true; do
  hg commit -m "commit: $(date)"
  sleep 60

Run it when you start to edit your file, and it will check for changes every minute, if there was changes, mercurial will make new commit. Also, as I've mention in comments, you can use at or cron for autocommits.

  • I've installed mercurial via Synaptic. I did the steps until hg comm -m 'first run'. At this point I got abort: no username supplied (see "hg help config"). I'm the only user of my computer. Anyway, I'll take a look at hg help config. – user15760 Apr 1 '13 at 11:02
  • Sorry, I forget about is (as my mercurial was configured a long time ago). Make fix. – Eddy_Em Apr 1 '13 at 13:20

I second the recommendation to use version control. It's a lot more flexible and more reliable than keeping backup files around, and it's easy to set up.

Nonetheless, if you want fine control over backup files (and over many other things), you can use Emacs. Set the version-control variable to t to make numbered backups and not just keep one backup file per session (put (setq version-control t) in your ~/.emacs). Press C-u C-x C-s instead of just C-x C-s when you want to create a new backup.

Another approach is to use a filesystem that makes the backups for you, regardless of whether the application knows anything about backups. CopyFS creates such a filesystem on top of any directory tree.


Looks like there's a doublesave plugin for gEdit. Although it uses a timestamp instead of an incrementing number.


Geany comes with a suitable plugin as well. I'm using Geany 1.23.1 on Lubuntu 13.10. Clicking on Tools, Plugin Manager shows this:

Plugin Manager dialog

In here, one can tick Save Actions and then, in Edit, Plugin Preferences, one can set up how the backups are to be saved:

Save Actions dialog


A bit late to the party here, but you can achieve unique backup functionality in nano (at least in the current Debian version 2.2.6) using the -B and -C flags.

From the Debian man page:

   -B (--backup)
          When saving a file, back up the previous version of it to the  current  filename
          suffixed with a ~.

   -C dir (--backupdir=dir)
          Set  the  directory  where  nano  puts  unique  backup files if file backups are

To make this default, create a bash alias for nano including the flags, and put it where appropriate (adding the line below to /home/username/.bash_aliases works for me):

alias nano='nano -BC /home/username/.nano_backups'

Which will yield backups in the specified directory like:

$ ls /home/username/.nano_backups

With vv you can have up to 100 backup files. vv is an addon tool for any editor and can save, recover, list, etc hidden backups, fully automatic.

See http://fex.belwue.de/fstools/vv.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy