Welcome to WebmasterWorld Guest from 54.221.54.252

Forum Moderators: bakedjake

Message Too Old, No Replies

Hard link between files in linux

     
5:32 am on Oct 14, 2006 (gmt 0)

New User

10+ Year Member

joined:Sept 7, 2006
posts:16
votes: 0


What is the difference between ln -s and ln -S . both are used for hard linking of files or folders.
10:02 pm on Oct 14, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 31, 2003
posts:1316
votes: 0


ln is used for hard linking
ln -s is used for symbolic linking

As for the -S, it's an option to be used when making automatic backups of the destination file, which I've never done.

2:01 am on Oct 15, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member jtara is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 26, 2005
posts:3041
votes: 0


You've got the terminology a bit backwards.

ln -s is used to create symbolic links. Just plain ln creates "hard links". Some people refer to symbolic links as "soft links".

A hard link is simply an additional directory entry pointing to the same data. They're a bit of a pain from a bookkeeping perspective, as it's impossible to easily determine where they point. You can only tell how MANY of them there are pointing to the same data. But they're a bit faster than symbolic links. And when you delete a file via a hard link, the file and all the links go away. Not so with a symbolic link.

The -S option, as pointed-out above, has nothing to do with hard or soft links. It deals with adding a suffix to backup files.

6:31 am on Oct 15, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 31, 2003
posts:1316
votes: 0


when you delete a file via a hard link, the file and all the links go away. Not so with a symbolic link.

Not quite. If you hard-link file A to file B, you can delete either one and the other will still be there intact.

But with symbolic links, if you delete the file itself, the link becomes useless.

Also, hard links work only between files on the same filesystem, and not directories. Symbolic links will work across filesystems, and directories too.

7:01 am on Oct 15, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member jtara is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 26, 2005
posts:3041
votes: 0


Not quite. If you hard-link file A to file B, you can delete either one and the other will still be there intact

Sorry... correct. The file will disappear when you have removed all of the hard links (including the original).

There's no difference between a normal directory entry and a hard link. A hard link is simply a duplicate directory entry.

BTW, Windows supports symbolic links, though it's an obscure, poorly-documented feature that has some quirks.