{"id":12,"date":"2007-08-08T18:54:49","date_gmt":"2007-08-08T10:54:49","guid":{"rendered":"http:\/\/www.sysadmindayph.com\/blog\/?p=12"},"modified":"2007-08-08T18:59:23","modified_gmt":"2007-08-08T10:59:23","slug":"links","status":"publish","type":"post","link":"https:\/\/www.sysadmindayph.com\/blog\/links\/","title":{"rendered":"Soft and Hard Links&#8230; Explained"},"content":{"rendered":"<p>A friend and I were kind of reviewing some HPUX\/Solaris commands and ideas. She asked \u201cWhat were the difference between hard and soft links?\u201d.  Unable to get the answer at once, I of course consulted my Solaris Administration guide. I also got curious cause I really don\u2019t mind what their difference is, all I care about is that they were linked and that\u2019s it. So here goes the difference between Mr Hard and Ms. Soft Link\u2026.<\/p>\n<p>First, what are links? A <a title=\"iddle00372\" name=\"iddle00372\"><\/a><a title=\"iddle00371\" name=\"iddle00371\"><\/a>link is a <strong>pointer<\/strong> to another file or directory. Links provide a mechanism for multiple file names to reference the same data on disk.<\/p>\n<p><strong>Soft (Symbolic) Links<\/strong> is a shortcut (like a desktop shortcut on Windows). The syntax for creating a symbolic link is as follows:<\/p>\n<blockquote>\n<pre>ln -s source-file link-name<\/pre>\n<\/blockquote>\n<p>Now when you list the contents of the directory you see two files:<\/p>\n<blockquote>\n<pre>3588 -rw-r--r--   1 chelsy staff       30 Jun 17 17:51 file1<\/pre>\n<pre>3594 lrwxrwxrwx   1 chelsy staff       5  Jun 17 18:09 link1 -&gt; file1<\/pre>\n<\/blockquote>\n<p><strong>Hard link<\/strong> is more difficult to determine, because they are not so obvious when viewed with the <tt>ls -li<\/tt> command. The syntax is :<\/p>\n<p>ln file1 link1  <em>(No \u2013s?)<\/em><\/p>\n<p>What you could notice is that the inode in each file is the same when you list them. Notice the first column, all of which have 1898 value, meaning the files in the list have the same inode number, therefore, is the same file.<\/p>\n<blockquote>\n<pre>1898  4 -rwxr--r--   5 root   sys    3506 Jan 10  2005 \/etc\/init.d\/init.wbem<\/pre>\n<pre>1898  4 -rwxr--r--   5 root   sys    3506 Jan 10  2005 \/etc\/rc0.d\/K36wbem<\/pre>\n<pre>1898  4 -rwxr--r--   5 root   sys    3506 Jan 10  2005 \/etc\/rc1.d\/K36wbem<\/pre>\n<pre>1898  4 -rwxr--r--   5 root   sys    3506 Jan 10  2005 \/etc\/rc2.d\/S90wbem<\/pre>\n<\/blockquote>\n<p>1898  4 -rwxr&#8211;r&#8211;   5 root   sys    3506 Jan 10  2005 \/etc\/rcS.d\/K36wbem<\/p>\n<p><strong><em>So what is the difference then?<\/em><\/strong><em> <\/em>Except for the syntax with no \u2013s in the option, try deleting the source file in the soft link.<\/p>\n<p>In Soft Link, if you remove <tt>file1<\/tt>, the source file, <tt>link1<\/tt> will still exist, but it points to a file that does not exist. So when you open link1,<\/p>\n<blockquote>\n<pre>cat link1<\/pre>\n<\/blockquote>\n<p>The <tt>cat<\/tt> command can&#8217;t print out the contents of the file, so you get this message:<\/p>\n<blockquote>\n<pre>cat: Cannot open link1<\/pre>\n<\/blockquote>\n<p>In Hard Link, if you remove file, the source file, link1 will still exist and you will still be able to open it. The data will not be deleted until you destroy the last file that shares this inode number. Nice huh???<\/p>\n<p><strong>Pros and Cons???<\/strong><\/p>\n<p>A hard link cannot span file systems; it can only point to another file located within its file system. The reason is that hard links all share an inode number. Each file system has its own set of inode numbers; therefore, a file with inode number 1234 in the <tt>\/export\/home<\/tt> file system may not even exist in the <tt>\/usr<\/tt> file system.<\/p>\n<p>An advantage of a symbolic link over a hard link is that you can create a symbolic link to a file that does not yet exist. You cannot create a hard link unless the source file already exists.<\/p>\n<p>Makes sense?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A friend and I were kind of reviewing some HPUX\/Solaris commands and ideas. She asked \u201cWhat were the difference between hard and soft links?\u201d. Unable to get the answer at once, I of course consulted &hellip;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,3],"tags":[],"class_list":["post-12","post","type-post","status-publish","format-standard","hentry","category-solaris","category-unix"],"_links":{"self":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":0,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}