Welcome to WebmasterWorld Guest from 54.196.212.62

Forum Moderators: bakedjake

Message Too Old, No Replies

Hard link between files in linux

     

rajeshk98

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

5+ Year Member



What is the difference between ln -s and ln -S . both are used for hard linking of files or folders.

mcavic

10:02 pm on Oct 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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.

jtara

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

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



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.

mcavic

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

WebmasterWorld Senior Member 10+ Year Member



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.

jtara

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

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



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.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month