Two files, same directory, same name...

Tom Ivar Helbekkmo tih at barsoom.nhh.no
Sat Jun 16 02:00:34 AEST 1990


Tom Betz asked about a problem he has, where it seems that two of his
files have the exact same name.  Since this is a situation that's easy
to get into, but much harder to solve unless you know how, and since
it can quickly lead to lost data, here's a somewhat verbose explanation:

The problem is that one of your two files has a name that contains a
non-printing character.  This happens now and then...  Here's an `ls
-la` of a directory I just created to illustrate it:

% ls -la
total 8
drwxr-xr-x   2 tih      users         80 Jun 15 17:41 .
drwxr-xr-x   3 tih      users        704 Jun 15 17:41 ..
-rw-r--r--   1 tih      users         21 Jun 15 17:40 Testfile
-rw-r--r--   1 tih      users         42 Jun 15 17:41 Testfile
%

And here's the `od -c .` output showing what the directory entry
actually contains (this is a System V directory, yours will look
different if you're running BSD Unix):

% od -c .
0000000 223   &   .  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000020 270 017   .   .  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000040 236   <   T   e   s   t   f   i   l   e  \0  \0  \0  \0  \0  \0
0000060   b   B   T   e   s   t   f   i   l   e 004  \0  \0  \0  \0  \0
%

Notice the byte with the value 004 (or Ctrl-D) there?  One file is
actually named "Testfile", while the other one is called "Testfile^D"!
This might happen, in some applications, if you start to type a
filename, and then accidentally hit a non-printing character while
doing it.  (I did it by going into an editor, reading in Testfile, and
then specifying Testfile^D when I wrote it back out.)

To fix this one, without losing either file, I would do:

% ls
Testfile
Testfile
% mv Testfile File.1
% ls
File.1
Testfile
% mv Testfile* File.2
% ls
File.1
File.2
%

The trick is to be able to catch the file with the unknown character
in it alone -- and I did it by first moving the file that had the
correct name (since I specified it as it looked).  After that, I could
use a wildcard to match the remaining file (thus not having to type
the unknown character), and everything is now OK!

-tih
-- 
Tom Ivar Helbekkmo, NHH, Bergen, Norway.  Telephone: +47-5-959205
tih at barsoom.nhh.no, thelbekk at norunit.bitnet, edb_tom at debet.nhh.no



More information about the Comp.unix.questions mailing list