|
How do Unix / Linux "hard links" work?
A reader writes:
So, I'm partway through your book, and I want to check on hard links. When you say it creates another door to the same body of data, is that literally true? For example, if all I have in my ./Documents directory is 001.doc (size 512K), and I hard link as hardlink.doc then run ls, do I see A or B? In terms of your specific question, the system will view the two files as having separate content. This can be demonstrated thusly: $ du 249 . $ ls -l total 248 -rw-r--r-- 1 dtint vuser 247034 Aug 24 03:24 some.data Now let's create some hard links. Notice "ls" reports 248 blocks in this directory $ ln some.data link2 $ ln some.data link3 $ ln some.data link4 $ ls -l total 992 -rw-r--r-- 4 dtint vuser 247034 Aug 24 03:24 link2 -rw-r--r-- 4 dtint vuser 247034 Aug 24 03:24 link3 -rw-r--r-- 4 dtint vuser 247034 Aug 24 03:24 link4 -rw-r--r-- 4 dtint vuser 247034 Aug 24 03:24 some.data As expected, "ls" now reports 992 blocks in use, seeing each of the new hard linked files as new data. But... notice what "du" reports, since it actually looks deeper into the file system: $ du 249 .As you can see, some elements of the file system see hard links as new and separate data entities (e.g. "ls"), while others dig further into the file system to ascertain actual data blocks used and associated with the current location (e.g., "du"). This makes sense because otherwise if you had lots of hard links you could theoretically end up in a situation where you have greater than 100% disk space utilization, which would clearly be a bit confusing at best!
Categorized:
Unix and Linux Help
(Article 3733,
Written by Dave Taylor)
Tagged: Previous: Extracting the correct column with "ps" and "awk" Next: How not to build traffic: respond to email solicitations of Link Exchanges Subscribe!
Another way to look at hard links - they share the same inode no matter what. Do this with ls -i and it will become obvious. The disadvantage of hard links is that you cannot hard link across 2 separate drives on your system ... say hda and hdb (when you can with soft or symlinks) the information was very use full. please post some on cron jobs. Thanks in advance Posted by: anjan at May 22, 2009 5:28 AMI just tested hardlinks on an NFS share, and it worked! .. i knew that symbolic links didn't work on NFS so i tried hard links and it worked that leads me to believe you can also hard link between different harddrives or can anyone explain why it wouldn't work? Posted by: Azeem at June 24, 2009 9:23 PMI have something to say, now that you mention it, but ...
I do have a comment, now that you mention it!
|
Recommended
Recent Entries
Search
I Need Help!
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and RSS Feeds Building Web Site Traffic Business and Management CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above Facebook Help Google Plus Help HTML and CSS Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Mac OS X Help Pay Per Click (PPC) Advertising Search Engine Optimization (SEO) Shell Script Programming Tech Support Video Help The Writing Business Twitter, LinkedIn and Social Network Help Unix and Linux Help Video Game Tips and Help Windows PC Help WordPress Help |