{"id":972,"date":"2024-02-11T12:54:41","date_gmt":"2024-02-11T12:54:41","guid":{"rendered":"http:\/\/shijuvarghese.com\/?p=972"},"modified":"2024-06-15T22:52:04","modified_gmt":"2024-06-15T22:52:04","slug":"redhat-links-between-files","status":"publish","type":"post","link":"http:\/\/shijuvarghese.com\/?p=972","title":{"rendered":"Redhat &#8211; Links between files"},"content":{"rendered":"<p>Every file or folder created in a Linux system is associated with an iNode. The name given to the file is mapped to the inode created.<\/p>\n<p style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><strong>Hard Link<\/strong><\/span><\/p>\n<p><a href=\"http:\/\/shijuvarghese.com\/wp-content\/uploads\/2024\/02\/Linux-Hardlink.jpg\" rel=\"attachment wp-att-973\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-973\" src=\"http:\/\/shijuvarghese.com\/wp-content\/uploads\/2024\/02\/Linux-Hardlink.jpg\" alt=\"Linux Hardlink\" width=\"321\" height=\"281\" srcset=\"http:\/\/shijuvarghese.com\/wp-content\/uploads\/2024\/02\/Linux-Hardlink.jpg 321w, http:\/\/shijuvarghese.com\/wp-content\/uploads\/2024\/02\/Linux-Hardlink-300x263.jpg 300w\" sizes=\"auto, (max-width: 321px) 100vw, 321px\" \/><\/a><\/p>\n<p>The below command creates two\u00a0<strong>hard<\/strong> links to the a new files<\/p>\n<p style=\"padding-left: 30px;\"><strong>[root@centos9vm ~]#<\/strong> <em>touch shiju_default.txt<\/em><br \/>\n<strong>[root@centos9vm ~]#<\/strong> <em>ls -l | grep shiju<\/em><br \/>\n-rw-r&#8211;r&#8211;. 1 root root 0 Feb 11 18:26 shiju_default.txt<\/p>\n<p style=\"padding-left: 30px;\"><strong>[root@centos9vm ~]#<\/strong> <em>link shiju_default.txt shiju_hardlink1.txt<\/em><br \/>\n<strong>[root@centos9vm ~]#<\/strong> <em>link shiju_default.txt shiju_hardlink2.txt<\/em><\/p>\n<p style=\"padding-left: 30px;\"><strong>[root@centos9vm ~]#<\/strong> <em>ls -l | grep shiju<\/em><br \/>\n-rw-r&#8211;r&#8211;. <strong>3<\/strong> root root 0 Feb 11 18:26 shiju_default.txt<br \/>\n-rw-r&#8211;r&#8211;. <strong>3<\/strong> root root 0 Feb 11 18:26 shiju_hardlink1.txt<br \/>\n-rw-r&#8211;r&#8211;. <strong>3<\/strong> root root 0 Feb 11 18:26 shiju_hardlink2.txt<\/p>\n<p>Notice the value &#8220;<strong>3<\/strong>&#8221; in the above result of &#8220;ls&#8221; command. The\u00a0<strong>3<\/strong> indicates that there are three filenames associated with the same iNode.<\/p>\n<p>The below command shows the inode ID <strong>4300558\u00a0<\/strong>and the files associated with it<\/p>\n<p style=\"padding-left: 30px;\">[root@centos9vm ~]# ls -il shiju*<br \/>\n<strong>4300558<\/strong> -rw-r&#8211;r&#8211;. <strong>3<\/strong> root root 0 Feb 11 18:26 shiju_default.txt<br \/>\n<strong>4300558<\/strong> -rw-r&#8211;r&#8211;. <strong>3<\/strong> root root 0 Feb 11 18:26 shiju_hardlink1.txt<br \/>\n<strong>4300558<\/strong> -rw-r&#8211;r&#8211;. <strong>3<\/strong> root root 0 Feb 11 18:26 shiju_hardlink2.txt<\/p>\n<p>Deleting the default file or a hard link will not delete the inode nor the other filenames associated with the inode.<\/p>\n<p style=\"padding-left: 30px;\"><strong>[root@centos9vm ~]#<\/strong> rm -f shiju_default.txt<br \/>\n<strong>[root@centos9vm ~]#<\/strong> ls -il shiju*<br \/>\n4300558 -rw-r&#8211;r&#8211;. 2 root root 0 Feb 11 18:26 shiju_hardlink1.txt<br \/>\n4300558 -rw-r&#8211;r&#8211;. 2 root root 0 Feb 11 18:26 shiju_hardlink2.txt<\/p>\n<p>We cannot create hard links between files or folders in different partitions.<\/p>\n<p style=\"text-align: center;\"><span style=\"text-decoration: underline;\"><strong>Soft Link<\/strong><\/span><\/p>\n<p>A soft-link links a filename to a default file, not to the actual inode directly.<\/p>\n<p style=\"padding-left: 30px;\"><strong>[root@centos9vm ~]#<\/strong> touch shiju_default.txt<br \/>\n<strong>[root@centos9vm ~]#<\/strong> ln -s shiju_default.txt shiju_default-sLink.txt<br \/>\n<strong>[root@centos9vm ~]#<\/strong> ls -il<br \/>\n<strong>[root@centos9vm ~]# ls -il | grep shiju<\/strong><br \/>\n4300559 lrwxrwxrwx. 1 root root 17 Feb 11 20:04 shiju_default-sLink.txt -&gt; shiju_default.txt<br \/>\n4300558 -rw-r&#8211;r&#8211;. <strong>1<\/strong> root root 0 Feb 11 18:41 shiju_default.txt<\/p>\n<p>We can create hard links between files or folders even in different partitions.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Every file or folder created in a Linux system is associated with an iNode. The name given to the file is mapped to the inode <a class=\"mh-excerpt-more\" href=\"http:\/\/shijuvarghese.com\/?p=972\" title=\"Redhat &#8211; Links between files\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":252,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,31,30],"tags":[],"class_list":["post-972","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-rhel-4","category-rhel-9"],"_links":{"self":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/972","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=972"}],"version-history":[{"count":5,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/972\/revisions"}],"predecessor-version":[{"id":978,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/972\/revisions\/978"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/media\/252"}],"wp:attachment":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=972"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=972"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=972"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}