-
Website
http://www.tech-recipes.com/ -
Original page
http://www.tech-recipes.com/rx/173/create-a-hard-link-in-unix/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
davak
83 comments · 1 points
-
Web Design
3 comments · 1 points
-
danishbacker
9 comments · 1 points
-
flexinfo
11 comments · 1 points
-
Tonychelle
4 comments · 1 points
-
-
Popular Threads
-
Facebook: How To Get Only Status Updates on Your FB Home Page
1 week ago · 4 comments
-
Firefox: Enable Case Sensitive Searches When Using Find (Ctrl+F)
4 days ago · 1 comment
-
Windows 7: How To Disable Live Preview for Taskbar Thumbnails
1 week ago · 2 comments
-
Gmail: How to block a sender from your inbox
3 weeks ago · 3 comments
-
Our first iPhone game GreenThumb available in the App Store
3 weeks ago · 2 comments
-
Facebook: How To Get Only Status Updates on Your FB Home Page
The UNIX file system stores files in inodes. The filesystem table contains a list of filenames, and the pointer to the inode in which that file exists.
A hard link creates a second entry in the filesystem table pointing to the same inode of the file. This can be illustrated with the ls command very easily:
1: # touch /this
2: # ln /this /root/that
3: # ls -i /this /root/that
4: 18 /root/that 18 /this
5: # rm -f /this
6: # ls -i /root/that
7: 18 /root/that
What did I do above? Here's a play-by-play:
1: create a file (/this)
2: hardlink the file (/this) to another file (/root/that)
3: ask to see the inodes that the files exist in
4: note that the inode numbers are identical - 18
5: delete the original file
6: show me the inode of the other file again
7: it's still the same.
In the above example, Inode 18 is occupied only once, and is referenced by two different path/filenames. Removing the first file doesn't in any way affect the second. The actual inode is still in use by the second reference. As soon as you remove all references, the inode is considered unused and can have new data written to it.
One caveat - hard links cannot span mount points. My own home directory is mounted from another disk, for example, so I cannot hardlink from /this to /home/bofh/that. The other caveat is that you cannot hard link directories.
Soft links are really pointers to a pointer. ls -i on both files will still show they are pointing at the same inode... but if you remove the original file, then the inode is actually completely dereferenced. The plus-side is that soft links can span mount points and you can soft link directories. The downside is that if you remove the original then the link is broken.
So imagine you are compiling a kernel, trying different patchsets. You dont want to make many "real" copies of the same files, as it takes lot of space and time to do so. Then you could just do hardlinks to the files. And then, only the modified files will actually exist:
cd /usr/src/
cp -rl linux-clean linux-experiment
then you will see, the new folder takes lot less space than the original one but is however fully funcional :) you can compile, apply patches, etc....