{"id":2411,"date":"2013-07-24T11:19:34","date_gmt":"2013-07-24T03:19:34","guid":{"rendered":"http:\/\/rmohan.com\/?p=2411"},"modified":"2013-07-24T11:22:40","modified_gmt":"2013-07-24T03:22:40","slug":"soft-link-and-hard-link-in-linux","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=2411","title":{"rendered":"Soft Link and Hard Link in Linux"},"content":{"rendered":"<p>Linux provides the user&#8217;s to save the same data of a file with one or more different names in different places of a same partition in two ways :<\/p>\n<ol>\n<li>Hard Link<\/li>\n<li>Symbolic Link<\/li>\n<\/ol>\n<div>Hard link is \u00a0a directory entry which is associated with a file on a\u00a0file system\u00a0 The term is used to represent multiple links to a single file on a\u00a0file system. lets say we have created two different files with same data and opened one of the file and made some changes to the files, we can see the changes applied to the file when the other file is opened.<\/div>\n<div><\/div>\n<div>Hard links can only be created to files on the same volume. If a link to a file on a different volume is needed, it may be created with a\u00a0<a title=\"Symbolic link\" href=\"http:\/\/en.wikipedia.org\/wiki\/Symbolic_link\">symbolic link<\/a>.<\/div>\n<div><\/div>\n<div>How to Create Hard Link in Linux ..?<\/div>\n<div><\/div>\n<div>Use the following syntax to create a\u00a0hard link\u00a0between two files on the same\u00a0file system.<\/div>\n<div><\/div>\n<div>ln {source} {link}<\/div>\n<div><\/div>\n<div>Where ,<\/p>\n<ul>\n<li>Source is an existing file.<\/li>\n<li>link is the file to create(a hard link).<\/li>\n<\/ul>\n<div>To create a hard link for a foo file, follow the below commands.<\/div>\n<div><\/div>\n<div><\/div>\n<\/div>\n<div>echo &#8216;This is a test file for Hard Link&#8217; &gt; foo.txt<br \/>\nln foo bar<br \/>\nll -li bar fooHere is how output looks like &#8230;..[root@localhost prem]# ls -li bar.txt foo.txt<br \/>\n152667 -rw-r&#8211;r&#8211; 2 root root 34 May 18 21:07 bar.txt<br \/>\n152667 -rw-r&#8211;r&#8211; 2 root root 34 May 18 21:07 foo.txt<\/p>\n<div>Symbolic Link is also known as symlink &amp; soft link is a special type of file which contains the reference of other file, just like a pointer which stores the values to which it points.\u00a0Similarly\u00a0symbolic link stores the reference of other files, so as if any changes are ,made on one file then automatically the link which stores the reference of other file will automatically gets updated. Symlink is major used when two files are on different partitions in Linux.<\/div>\n<div><\/div>\n<div>How to Create Symlink or Soft Link in Linux ..?<\/div>\n<div><\/div>\n<div>Use the below syntax to create soft link:<\/div>\n<div><\/div>\n<div>ln -s {target filename} {symbolic file name}<\/div>\n<div>\u00a0-s option for soft link<\/div>\n<div><\/div>\n<div>For example :<\/div>\n<div><\/div>\n<div>ln -s \/home\/httpd\/index.html \/home\/prem\/fwss.html<\/div>\n<div>ls -l<\/div>\n<div><\/div>\n<div>Here is the sample output.<\/div>\n<div>\u00a0lrwzrwxrwx 1 prem prem16 2013-05-16 10:13 index.html &gt;\/home\/prem\/fwss.html<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Linux provides the user&#8217;s to save the same data of a file with one or more different names in different places of a same partition in two ways :<\/p>\n<p> Hard Link Symbolic Link Hard link is a directory entry which is associated with a file on a file system The term is used to represent [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2411"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2411"}],"version-history":[{"count":3,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2411\/revisions"}],"predecessor-version":[{"id":2413,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2411\/revisions\/2413"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}