[NTLUG:Discuss] Is there a way to change permissions of a link

Richard Cobbe cobbe at directlink.net
Wed Nov 1 13:29:42 CST 2000


Lo, on Wednesday, November 1, Kyle_Davenport at compusa.com did write:

> 
> 
> EMI: links in unix are not like the silly shortcuts in windows.  A soft
> link is simply a pointer in its directory's inode table to the target
> inode.  A hard link is actually the same file and inode by another name.
> Many file commands like cp, mv, tar, find... have arguments that change
> how they treat links (whether they dereference them or not)
> 

Not entirely true.

Each file on a unix/linux filesystem has an inode associated with it.  This
inode contains things like owner, group, permissions, and the location of
the file's data blocks on disk.  The filename is NOT in the inode.

A directory entry is simply a (name, inode) pair.  If I've got a file foo
in the current directory, and I do `ln bar foo' to create a "hard link",
this creates a new directory entry pointing to the same inode, and thus the
same data blocks.

A soft link is (conceptually) a very short file of a special type.  This
file contains the *filename*, not the inode number, of the target file.
So, for instance, `ln -s baz foo' will create a new inode for baz, store
"foo" in its contents, and create a new directory entry for baz which
points to this new inode.

Upon finding a symlink, the kernel path-lookup algorithm will textually
substitute the link's value (here, "foo") in the path string in place of
the link, then restart the algorithm (in case there are still more symlinks
to be resolved).

However, you are correct, both hard and soft links are far more capable and
consistent than Windows's shortcuts.  As far as I can tell, those are of
interest ONLY to the explorer/desktop.  Trying to open a shortcut in, say,
MS Word will get you an error (unless they've added code to Word to follow
shortcuts; it wasn't there the last time I used Word).

Those commands like rm, cp, and tar which (can) behave differently for
links will only change their behavior for symlinks, not hard links.
There's actually no way for a process to distinguish between a normal file
and a hard link to that file---primarily because, at the filesystem level,
there *IS* no difference.

Richard



More information about the Discuss mailing list