Glindra
Documentation Index Download
Command Line File Handling and ASCII Tools

File Version Numbers

How It Works

How version numbers work under VMS

Digital's VMS operating system has file version numbers built into the file system. When you create a file with a new name under VMS, it gets version number 1. Whenever you edit the file, or create a new file with the same name in the same directory, the new or edited file will get the next higher version number. The previous version or versions of the file remain on disk, until they are purged away manually with the purge command.

This is a very useful feature, but unfortunately neither Linux nor Windows has it built into the file system.

How Emacs does it

The Emacs editor can be set to emulate version numbers under both Linux and Windows.

To turn this feature on, you set the variable version-control to t in the .emacs start-up file. When you edit a file, the latest version will keep the original filename, without any additions. The earlier versions will be renamed, so that a version number is added.

If, for instance, you have been editing a file called myfile.txt, you may find the following files in your directory:

myfile.txt.~1~
myfile.txt.~2~
myfile.txt.~3~
myfile.txt

Here myfile.txt is the current version of the file, myfile.txt.~3~ is the previous version, myfile.txt.~2~ is the version before that, etc. The next time you edit the file, the version that is called myfile.txt will be renamed myfile.txt.~4~, and the new version will be called just myfile.txt.

The d directory will sort the files so that the most current file version comes last.

Example (Windows)
Directory of e:\work\

2 kb 12-Jan-2005 14:58:55 myfile.txt.~1~
2 kb 14-Jan-2005 02:17:30 myfile.txt.~2~
0 14-Jan-2005 14:07:43 myfile.txt.~3~
0 16-Jan-2005 13:35:05 myfile.txt
----------
4 kb total, 4 files

Glindra version numbers

The Glindra version numbers are work in the same way as these version numbers used by Emacs.

When a Glindra program creates a file, it will first check to see if that filename already exists. If it does, it will look for any previous old versions of that file, and determine the highest version number that is in use for this file. It will then do a rename operation on the existing file (which did until this time not have any version number), and assign the next higher version number to it. After these steps have been completed, the new file will be created, without any version number.

The fact that the current version of the file does not have any version number as part of the physical filename ensures a reasonably smooth interoperability between the Glindra programs and other programs which do not use version numbers. A non-Glindra program that is asked to create a file myfile.txt will simply overwrite any existing file with the same name, so that the filename myfile.txt refers to the newly created file. A Glindra program will also create the new file under the name myfile.txt. The only difference is that the previous version will still be available under a different name, until you explicitly delete it.

For input files, the Glindra programs will interpret a file specification without any version number to mean the file with a physical file name without a version number if that file exists, or otherwise the file with the highest version number.

Under most circumstances, there will be a file without any version number, since this is how the most recent version of the file is normally stored. However, since the whole idea behind version numbers is that if you make a mistake when you create a file you can delete it and revert to the previous version, it makes sense that programs that are "version number aware" should automatically be able to find the highest version available. If it is a Glindra program that has to be re-run, you can just delete the erroneous last version and continue as you were.

For non-Glindra programs you will have to handle this situation manually, by either explicitly renaming the highest version of the file so that it no longer contains a version number, or by specifying the exact physical file name including the version number.

The tildes are optional

When you give a file specification that includes an explicit version number to a Glindra program, you can omit the tilde ~ characters in the version number. If you write myfile.txt.2, this refers to the file that is stored on disk under the name myfile.txt.~2~.

(Tildes are very inconvenient to type on a Swedish keyboard.)

Relative (negative) version numbers

Negative version numbers can be used to specify a version relative to the last version.

a.xyz. Specifies the last (current) version of the file. Normally this will be the disk file a.xyz with no version number at all, but if no such file exists, it will be the a.xyz file with the highest version number.
a.xyz.-1
The second to last version of the file, whichever actual (positive) version number it may have on disk.
a.xyz.-2
The version before that, etc.

Note that the number 0 is not a valid version number, and it cannot be used to specify the last version of the file, as it could on VMS. If you specify a filename that ends with .0 it will be treated as a part of the extension.

It is recommended that you avoid naming files so that they end with .0, since it becomes rather confusing together with the version numbers, even if it technically works correctly.


Reverting To An Earlier Version

When a program asks for an input file, you specify the filename without any version number, under all normal circumstances. Even if the file was created by a program that used version numbers, the most current version will be the one without any explicit version number in its filename on disk.

The exception comes when you want to revert to an earlier version of a file. There are three different ways of doing this. You can either use the good version directly, rename it so that it becomes the last version, or delete the bad version(s) of the file.

Use the good version directly

Suppose we have the following files:

Directory of e:\work\

2 kb 12-Jan-2005 14:58:55 myfile.txt.~1~
2 kb 14-Jan-2005 02:17:30 myfile.txt.~2~
0 14-Jan-2005 14:07:43 myfile.txt.~3~
0 16-Jan-2005 13:35:05 myfile.txt
----------
4 kb total, 4 files

We now realize that there is something wrong with the two last versions of the file (since they are empty), and that we'll have to start again with myfile.txt.~2~ and redo the last two steps. We then specify myfile.txt.~2~, including the version number, as the input file to the first program that has to be re-run. After that, we're back on the same track we were before.

Rename the good version

Alternatively, we can rename the version that we want so that it becomes the current version, without any explicit version number. This can be done very conveniently with the rena command. If no output file name is given, the default is to rename the file so that it becomes the last version.

Continuing with the example, the command

> rena myfile.txt.2

would give

Directory of e:\work\

2 kb 12-Jan-2005 14:58:55 myfile.txt.~1~
0 14-Jan-2005 14:07:43 myfile.txt.~3~
0 16-Jan-2005 13:35:05 myfile.txt.~4~
2 kb 14-Jan-2005 02:17:30 myfile.txt
----------
4 kb total, 4 files
Delete the bad version(s)

The third method is to delete the bad version or versions. The command

> dele myfile.txt.

deletes the highest version of the file, but leaves all the earlier ones as they were.

The result after issuing that command would be:

Directory of e:\work\

2 kb 12-Jan-2005 14:58:55 myfile.txt.~1~
2 kb 14-Jan-2005 02:17:30 myfile.txt.~2~
0 14-Jan-2005 14:07:43 myfile.txt.~3~
----------
4 kb total, 3 files


To get rid of the highest remaining version of the file, we give the same command again:

> dele myfile.txt.

Although the highest version now has an explicit version number as part of its filename on disk, the dele command will find it and delete it.

The result will be:

Directory of e:\work\

2 kb 12-Jan-2005 14:58:55 myfile.txt.~1~
2 kb 14-Jan-2005 02:17:30 myfile.txt.~2~
----------
4 kb total, 2 files

(Needless to say, this method works best if there is just one bad version to remove. If there are more, it pays to make sure that you do not repeat the command once too much, and accidentally delete the good version as well.)

If the next step is to run the file through a program that understands version numbers, we can leave the filename like that. The Glindra programs will automatically figure out that the highest version of myfile.txt is myfile.txt.~2~, and use it when we specify myfile.txt without a version number.

We can also use the rena command to strip away any explicit version number on the highest version of the file. The command

> rena myfile.txt

will do this, and yield:

Directory of e:\work\

2 kb 12-Jan-2005 14:58:55 myfile.txt.~1~
2 kb 14-Jan-2005 02:17:30 myfile.txt
----------
4 kb total, 2 files


Output Files

Without version numbers
When you give an output file specification without any explicit version number, the program will first check to see if that file already exists. If it does, the existing file is renamed with a version number. The program can then open the new output file with the name without a version number.
Example

Suppose we already have a file called mydir.tmp :

Directory of e:\work\test\

2 kb 15-Feb-2005 10:42:31 mydir.tmp
----------
2 kb total, 1 file

If we give a command like

> d -output=mydir.tmp

which writes to the file mydir.tmp, the existing file will be renamed before the new file is created. The result might look like this:

Directory of e:\work\test\

2 kb 15-Feb-2005 10:42:31 mydir.tmp.~1~
57 kb 15-Feb-2005 11:56:38 mydir.tmp
----------
58 kb total, 2 files



If there's an extra "." after the extension, this is interpreted as making it explicit that we want a new last version of the file created, without any version number. The "." will not be part of the actual filename on disk, so in this context it is just redundant.

The command

> d -o=mydir.tmp.

has exactly the same meaning as the normal

> d -o=mydir.tmp
and will write to the file mydir.tmp, after having renamed any previously existing version of that file.
With version numbers
There is little reason why you would ever want to specify an explicit version number for an output file, but if you need to, you can.

The command

> d -o=mydir.tmp.17

will write to the file mydir.tmp.~17~, provided that file does not already exist. If it does, an error message is written out.  The existing file will not be overwritten, and no files will be renamed.

Note that the ~ tildes are added automatically to the version number.

Relative (negative) version numbers cannot be used in output specifications.