Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Links

Status
Not open for further replies.

godhelp

IS-IT--Management
Jan 30, 2003
48
Any idea HARD LINK and SOFT LINK....? What to do with this link...Any examples.
 
Hi,
Hard link refered to the same data as original file name therefore to delete file should be deleted its name and all hard links names.
Soft link refered to file name. In this case if file is deleted soft link refered to nowhere.
Regards Boris.
 
Hard link is another directory entry referencing the same filesystem inode. A soft link is a new inode which contains a pointer to the original filename. A soft link is prefixed l in the directory listing and can reference files on other filesystems. A soft link is constrained to the same filesystem as the original file and as such is not used as widely.

The size of the soft link is the length of the file to which it points plus 3 (for the '-> ' characters), the size of the hard link is the same as the size of the original file (it is effectively the same file). A file with a hard link remains until both the file and the hard link have been deleted. The number in ls before the owner name (2) indicates that there are 2 entries in the directory for this file.

# echo test >original_file
# ln original_file hard_link
# ln -s original_file soft_link
# ls -li

204255938 -rw-r--r-- 2 root other 5 Apr 16 16:12 hard_link
204255938 -rw-r--r-- 2 root other 5 Apr 16 16:12 original_file
204255600 lrwxrwxrwx 1 root other 13 Apr 16 16:13 soft_link -> original_file

# rm original file
#ls -i

204255938 -rw-r--r-- 1 root other 5 Apr 16 16:12 hard_link
204255600 lrwxrwxrwx 1 root other 13 Apr 16 16:13 soft_link -> original_file

# cat hard_link
test
# cat soft_link
cat: cannot open soft_link

Note the original file is still there due to the hard link but the number of directory entries is now 1. Also that the soft link points to a non-existant file so doesn't work anymore.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top