Em 16-07-2012 21:20, Baho Utot escreveu:

> On Monday, July 16, 2012 08:09:23 PM Bruce Dubbs wrote:
>> Baho Utot wrote:
>>> One could do this
>>>
>>> echo "test file" > test
>>> ln test link1
>>> ln test link2
>>> ln link1 link3
>>>
>>> ls -i
>>>
>>> 1333952 test 1333952 link1 1333952 link2 1333952 link3
>>>
>>> rm test
>>> ls -i
>>> 1333952 link1 1333952 link2 1333952 link3
>>>
>>> Doesn't link[1..3] point to "no where"  or garbage?
>>
>> No, they point to the data.  The rm command only deletes the data when
>> the link count goes to zero.  That is, rm removes the entry from
>> directory, and decrements the link count.
>>
>> $ echo "test file" > test
>> $ ls -l test
>> -rw-rw-r-- 1 bdubbs bdubbs 10 Jul 16 18:58 test
>> $ ls -i test
>> 1016053 test
>>
>> Note in the fist form the refernece count is 1.
>> $ ln test1 test
>> $ ls -l test*
>> -rw-rw-r-- 2 bdubbs bdubbs 10 Jul 16 18:58 test
>> -rw-rw-r-- 2 bdubbs bdubbs 10 Jul 16 18:58 test1
>> $ ls -1i test*
>> 1016053 test
>> 1016053 test1
>>
>> The link count is 2.
>>
>> $ rm test
>> $ cat test1
>> test file
>>
>> The data is still there.
>>
>> $ ls -l test*
>> -rw-rw-r-- 1 bdubbs bdubbs 10 Jul 16 18:58 test1
>>
>> but now the link count is 1.  This is also the reason you cannot rmdir a
>> directory that is not empty.  Note too that if you have two files with
>> the same inode, the system will copy the data if you edit either one.
>> You then have two different files, each with a count of 1.
> 
> That is weird, I would have expected both files to contain the same data.  
> Not 
> for the "system" to go behind your back and create two separate files.
> I guess I have too much C programming (from my old programming days) in my 
> line of thought.  I would have been nice to add data to one "file" and 
> readout 
> the data with the other (aka) dup file handles under C.
> 
> 
> 
> 
> 
> 
>>
>> Try it.
>>
>>    -- Bruce

$ echo "test file" > test
$ ls -l test
-rw-rw-r-- 1 fernando fernando 10 Jul 16 21:36 test
$ ls -i test
262710 test
$ ln test1 test
$ ls -l test*
-rw-rw-r-- 2 fernando fernando 10 Jul 16 21:36 test
-rw-rw-r-- 2 fernando fernando 10 Jul 16 21:36 test1
$ ls -1i test*
262710 test
262710 test1

$ echo "test file 2" >> test
$ diff -Nau test test1
$ ls -l test*
-rw-rw-r-- 2 fernando fernando 22 Jul 16 21:43 test
-rw-rw-r-- 2 fernando fernando 22 Jul 16 21:43 test1
$ ls -1i test*
262710 test
262710 test1

It seems changing one, the other is changed too.-- 
[]s,
Fernando
-- 
http://linuxfromscratch.org/mailman/listinfo/lfs-support
FAQ: http://www.linuxfromscratch.org/lfs/faq.html
Unsubscribe: See the above information page

Reply via email to