[NTLUG:Discuss] changing timestamp on symbolic link?

Steve Baker sjbaker1 at airmail.net
Wed Mar 12 10:13:41 CST 2003


Jack Snodgrass wrote:
> On Wed, 12 Mar 2003 08:43:13 -0600, Lance Simmons wrote:
> 
> 
>>I'd like to change the timestamp on a link (hard or symbolic, I don't
>>care which) without changing the timestamp on the target.
>>
>>Does anyone know how to do that?  
>>
>>If it's impossible, why do symbolic links have timestamps at all?
>>
> 
> ln -s -f real-file symbolic-name
> will force ( -f ) the link to be remade and it updates
> the timestamp on the link too. 
> 
> Not sure if this works with hard links. I only use / tested
> this on a symbolic link. 

No - it can't work with hard links - and I think it's important
to understand why:

Each file on disk has exactly one 'inode' which contains all the
information about the file *except* it's file name - which is kept
in the directory.   You can imagine a directory to be implemented
just like it was on the very early PDP-11 UNIX implementations as
a file containing a table of file names and inode numbers. (In the
early days, you could rename a file by editing the directory using
'vi'!)

Hence, the file create/update/read times are stored in the inode - not
in the directory.

In the case of a hard link, you just have two directory entries that
just happen to point to the same inode.  There is no 'real file' and
'link' - the two (or more) directory entries are exactly the same.

Since there is only one inode and hence only one set of timestamps,
there is no way for the two links to have the same timestamp.

Soft links were a kludge added into UNIX long after the original
implementation to get around certain limitations of the hard link
philosophy (eg: You can't hard-link across file systems or mounted
partitions, it's not possible to hard-link to a directory [unless
you are 'root' and have a taste for danger!]...hard-linking across
NFS partitions would be incredibly difficult to implement...and so
on).

A Soft link is in essence just a regular file that contains the
pathname of some other file.  Since the link is just a regular file,
it does have it's own inode and hence (in principle) can have it's
own timestamp.  However, that timestamp does not reflect changes to
the linked-to file and is generally rather useless - so most tools
don't use it.  That's "A Good Thing" because we are trying to pretend
that a soft link works just like a hard link (although it doesn't do
so in lots of vitally important ways!).

It's a shame that nobody took the time to think this stuff through
more carefully than they did right at day one.  Hard links are a very
elegant solution - and they are necessary to the way that things
like '.' and '..' work - but their limitations are annoying. Soft
links get around the limitations - but have annoying semantics
such as the ability to delete the 'target' file leaving a dangling
link behind - and all sorts of weird problems come up when you make
links to directories.

---------------------------- Steve Baker -------------------------
HomeEmail: <sjbaker1 at airmail.net>    WorkEmail: <sjbaker at link.com>
HomePage : http://www.sjbaker.org
Projects : http://plib.sf.net    http://tuxaqfh.sf.net
            http://tuxkart.sf.net http://prettypoly.sf.net
-----BEGIN GEEK CODE BLOCK-----
GCS d-- s:+ a+ C++++$ UL+++$ P--- L++++$ E--- W+++ N o+ K? w--- !O M- V-- PS++ PE- Y-- PGP-- t+ 5 X R+++ tv b++ DI++ D G+ e++ h--(-) r+++ y++++
-----END GEEK CODE BLOCK-----




More information about the Discuss mailing list