[X-Unix] Utility "ln" makes a copy instead of hard link?

Jerry Krinock jerry at ieee.org
Fri Apr 7 10:16:30 PDT 2006


EXPERIMENT:

1.  Create a text file named "1.txt" containing the text "Dog".
2.  Create a "hard link" by the command:
        ln 1.txt
    Expected result: Should create a "hard link" file
    Actual result: Error message:
        ln: ./1.txt: File exists
3.  Retry to make a "hard link" by the command:
        ln 1.txt 2.txt
    Result: Now there are two files, 1.txt and 2.txt.
4.  Open 1.txt and change contents to "Cat".
5.  Save.
6.  Open "2.txt" and read it.
7.  Expected result: "Cat".
8.  Actual result: "Dog"

Also, the calculated size of a directory containing a file and such a hard
link is twice the size of the one file by itself.

To summarize, ln seems to be making a copy instead of what is described as a
"hard link".  From the "man" manual of ln:

"The ln utility creates a new directory entry (linked file) which has the
same modes as the original file. It is useful for maintaining multiple
copies of a file in many places at once without using up storage for the
``copies''; instead, a link ``points'' to the original copy....By default,
ln makes hard links. A hard link to a file is indistinguishable from the
original directory entry; any changes to a file are effectively independent
of the name used to reference the file."

Is this a bug, or can I not understand English today?

Jerry Krinock




More information about the X-Unix mailing list