{"id":13564,"date":"2019-04-03T10:43:47","date_gmt":"2019-04-03T10:43:47","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13564"},"modified":"2019-04-03T10:43:47","modified_gmt":"2019-04-03T10:43:47","slug":"how-to-create-hard-and-symbolic-links-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/how-to-create-hard-and-symbolic-links-in-linux\/","title":{"rendered":"How to Create Hard and Symbolic Links in Linux"},"content":{"rendered":"<p>In Unix-like operating systems such as Linux, \u201c<a href=\"https:\/\/www.tecmint.com\/explanation-of-everything-is-a-file-and-types-of-files-in-linux\/\" target=\"_blank\" rel=\"noopener\">everything is a file<\/a>\u201d and a file is fundamentally a link to an inode (a data structure that stores everything about a file apart from its name and actual content).<\/p>\n<p>A hard link is a file that points to the same underlying inode, as another file. In case you delete one file, it removes one link to the underlying inode. Whereas a symbolic link (also known as soft link) is a link to another filename in the filesystem.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/file-and-directory-management-in-linux\/\" target=\"_blank\" rel=\"noopener\">How to Perform File and Directory Management<\/a><\/p>\n<p>Another important difference between the two types of links is that hard links can only work within the same filesystem while symbolic links can go across different filesystems.<\/p>\n<h3>How to Create Hard Links in Linux<\/h3>\n<p>To create a hard links in Linux, we will use\u00a0<strong>ln utility<\/strong>. For example, the following command creates a hard link named\u00a0<code>tp<\/code>\u00a0to the file\u00a0<code>topprocs.sh<\/code>.<\/p>\n<pre>$ ls -l\r\n$ ln topprocs.sh tp\r\n$ ls -l\r\n<\/pre>\n<div id=\"attachment_27561\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/create-a-hard-link.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27561\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/create-a-hard-link.png\" alt=\"Create a Hard Link to File\" width=\"732\" height=\"401\" aria-describedby=\"caption-attachment-27561\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27561\" class=\"wp-caption-text\">Create a Hard Link to File<\/p>\n<\/div>\n<p>Looking at the output above, using\u00a0<a href=\"https:\/\/www.tecmint.com\/tag\/linux-ls-command\/\" target=\"_blank\" rel=\"noopener\">ls command<\/a>, the new file is not indicated as a link, it is shown as a regular file. This implies that\u00a0<code>tp<\/code>\u00a0is just another regular executable file that points to the same underlying inode as\u00a0<code>topprocs.sh<\/code>.<\/p>\n<p>To make a hard link directly into a soft link, use the\u00a0<code>-P<\/code>\u00a0flag like this.<\/p>\n<pre>$ ln -P topprocs.sh tp\r\n<\/pre>\n<h3>How to Create Symbolic Links in Linux<\/h3>\n<p>To create a symbolic links in Linux, we will use same\u00a0<strong>ln utility<\/strong>\u00a0with\u00a0<code>-s<\/code>\u00a0switch. For example, the following command creates a symbolic link named\u00a0<code>topps.sh<\/code>\u00a0to the file\u00a0<code>topprocs.sh<\/code>.<\/p>\n<pre>$ ln -s ~\/bin\/topprocs.sh topps.sh\r\n$ ls -l topps.sh\r\n<\/pre>\n<div id=\"attachment_27562\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/create-a-symbolic-link.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27562\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/create-a-symbolic-link.png\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/create-a-symbolic-link.png 802w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/create-a-symbolic-link-768x111.png 768w\" alt=\"Create a Symbolic Link to File\" width=\"802\" height=\"116\" aria-describedby=\"caption-attachment-27562\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27562\" class=\"wp-caption-text\">Create a Symbolic Link to File<\/p>\n<\/div>\n<p>From the above output, you can see from the file permissions section that\u00a0<code>topps.sh<\/code>\u00a0is a link indicated by\u00a0<code>l:<\/code>meaning it is a link to another filename.<\/p>\n<p>If the symbolic link already exist, you may get an error, to force the operation (remove exiting symbolic link), use the\u00a0<code>-f<\/code>\u00a0option.<\/p>\n<pre>$ ln -s ~\/bin\/topprocs.sh topps.sh\r\n$ ln -sf ~\/bin\/topprocs.sh topps.sh\r\n<\/pre>\n<div id=\"attachment_27563\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/force-creation-of-existing-symbolic-link.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27563\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/force-creation-of-existing-symbolic-link.png\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/force-creation-of-existing-symbolic-link.png 802w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/force-creation-of-existing-symbolic-link-768x166.png 768w\" alt=\"Forcefully Create Symbolic Link\" width=\"802\" height=\"173\" aria-describedby=\"caption-attachment-27563\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27563\" class=\"wp-caption-text\">Forcefully Create Symbolic Link<\/p>\n<\/div>\n<p>To enable verbose mode, add the\u00a0<code>-v<\/code>\u00a0flag to prints the name of each linked file in the output.<\/p>\n<pre>$ ln -sfv ~\/bin\/topprocs.sh topps.sh\r\n$ $ls -l topps.sh\r\n<\/pre>\n<div id=\"attachment_27564\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/enable-verbosity-when-creating-a-symbolic-link.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-27564\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/enable-verbosity-when-creating-a-symbolic-link.png\" sizes=\"auto, (max-width: 802px) 100vw, 802px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/enable-verbosity-when-creating-a-symbolic-link.png 802w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2017\/10\/enable-verbosity-when-creating-a-symbolic-link-768x129.png 768w\" alt=\"Enable Verbose in Command Output\" width=\"802\" height=\"135\" aria-describedby=\"caption-attachment-27564\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-27564\" class=\"wp-caption-text\">Enable Verbose in Command Output<\/p>\n<\/div>\n<p>That\u2019s It! Do check out these following related articles.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/fdupes-find-and-delete-duplicate-files-in-linux\/\" target=\"_blank\" rel=\"noopener\">fdupes \u2013 A Command Line Tool to Find and Delete Duplicate Files in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/manage-file-types-and-set-system-time-in-linux\/\" target=\"_blank\" rel=\"noopener\">5 Useful Commands to Manage File Types and System Time in Linux<\/a><\/li>\n<\/ol>\n<p>In this article, we\u2019ve learned how to create hard and symbolic links in Linux. You can ask any question(s) or share your thoughts about this guide via the feedback form below.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/create-hard-and-symbolic-links-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Unix-like operating systems such as Linux, \u201ceverything is a file\u201d and a file is fundamentally a link to an inode (a data structure that stores everything about a file apart from its name and actual content). A hard link is a file that points to the same underlying inode, as another file. In case &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/03\/how-to-create-hard-and-symbolic-links-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Create Hard and Symbolic Links in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13564","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13564"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13564\/revisions"}],"predecessor-version":[{"id":13565,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13564\/revisions\/13565"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}