Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
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

4 Answers 4

up vote 4 down vote accepted

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

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

[ui]
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'
text_file.txt
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:

#!/bin/bash
while true; do
  hg commit -m "commit: $(date)"
  sleep 60
done

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.

share|improve this answer
    
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.

share|improve this answer

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

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.