When I have a file a.txt
and do ln -s a.txt b.txt
, then I edit a.txt
, a.txt
's timestamp changed. But when I edit b.txt
, b.txt
doesn't change its timestamp. Only a.txt
is changed. Why didn't b.txt
's timestamp change. And a.txt
's does.
Example:
$ ls -la
total 8
drwxr-xr-x 2 admin admin 4096 nov 5 16:53 .
drwxr-x--- 37 admin admin 4096 nov 5 16:53 ..
$ nano a.txt
$ ln -s a.txt b.txt
$ ls -la
total 12
drwxr-xr-x 2 admin admin 4096 nov 5 16:54 .
drwxr-x--- 37 admin admin 4096 nov 5 16:53 ..
-rw-r--r-- 1 admin admin 4 nov 5 16:54 a.txt
lrwxrwxrwx 1 admin admin 5 nov 5 16:54 b.txt -> a.txt
$ echo wait a minute
wait a minute
$ nano b.txt
$ ls -la
total 12
drwxr-xr-x 2 admin admin 4096 nov 5 16:56 .
drwxr-x--- 37 admin admin 4096 nov 5 16:53 ..
-rw-r--r-- 1 admin admin 9 nov 5 16:56 a.txt
lrwxrwxrwx 1 admin admin 5 nov 5 16:54 b.txt -> a.txt
$ echo wait a minute again
wait a minute again
$ nano a.txt
$ ls -la
total 12
drwxr-xr-x 2 admin admin 4096 nov 5 16:58 .
drwxr-x--- 37 admin admin 4096 nov 5 16:53 ..
-rw-r--r-- 1 admin admin 13 nov 5 16:58 a.txt
lrwxrwxrwx 1 admin admin 5 nov 5 16:54 b.txt -> a.txt
Look at this lines first:
-rw-r--r-- 1 admin admin 4 nov 5 16:54 a.txt
lrwxrwxrwx 1 admin admin 5 nov 5 16:54 b.txt -> a.txt
Then look at this, only a.txt's date changed when I edited b.txt
-rw-r--r-- 1 admin admin 9 nov 5 16:56 a.txt
lrwxrwxrwx 1 admin admin 5 nov 5 16:54 b.txt -> a.txt
Okay I know that b.txt is a symlink to a.txt. So you edit a.txt. But WHY didn't my OS change the date ONLY for a.txt. When I edit b.txt. It is much more useful to also change the date of b.txt.
But then you also can say that directory's won't change its date when I file is edited in the directory (i edited a file, and i used the directory). The directory is used to edit the file in it. But the os does change the directory date when i edit a file in it
b.txt
did NOT change. None of its contituents was modified, only its target.a.txt
was removed and replaced with a file calleda.txt
.a.txt
's data. Only that is edited. Or is the WHOLE file copied to the memory, file removed and recreated. So when I have a disk file of 4 GB I need to wait before the file is in memory, can be removed, and then can be recreated. That is what you are saying in 'a.txt is removed and replaced'.