{"id":29,"date":"2008-08-23T19:36:17","date_gmt":"2008-08-23T23:36:17","guid":{"rendered":"http:\/\/www.compdigitec.com\/labs\/?p=29"},"modified":"2008-08-23T19:36:17","modified_gmt":"2008-08-23T23:36:17","slug":"manipulating-symbolic-and-hard-links","status":"publish","type":"post","link":"http:\/\/www.compdigitec.com\/labs\/2008\/08\/23\/manipulating-symbolic-and-hard-links\/","title":{"rendered":"Manipulating symbolic and hard links on Linux and Windows"},"content":{"rendered":"<p>Symbolic and hard links are a very convenient feature of the Linux and UNIX operating systems &#8211; they enable you to create a short alias, use it to avoid duplicate data and much, much more. They are also availible on Windows to a limited extent &#8211; NTFS supports only hard links while FAT\/FAT32\/VFAT supports neither. However, using <a rel=\"nofollow\" href=\"http:\/\/www.cygwin.com\/\">Cygwin<\/a>, you can use Windows shortcuts as symbolic links, but that is as far as it gets.<\/p>\n<p>To create symbolic and hard links in Linux, make sure you have the <a rel=\"nofollow\" href=\"http:\/\/en.wikipedia.org\/wiki\/GNU_Core_Utilities\">GNU Coreutils<\/a> installed, which provides the ln utility.<\/p>\n<p>To create hard links and shortcuts in Microsoft Windows, <a href=\"\/labs\/files\/ln-win32.zip\">download ln for Windows<\/a> and place in a directory inside your %PATH%.<\/p>\n<ol>\n<li><code><span style=\"font-weight: bold;\">ln -s  <span style=\"font-style: italic;\">TARGET<\/span> <span style=\"font-style: italic;\">LINKNAME<\/span><\/span><\/code> &#8211; Creates a symbolic link (shortcut on Windows) called<span style=\"font-style: italic;\"> LINKNAME<\/span> that points to <span style=\"font-style: italic;\">TARGET<\/span>. This works with both folders and files.<\/li>\n<li><code><strong>ln <em>TARGETFILE<\/em> <em>LINKNAME<\/em><\/strong><\/code> &#8211; Creates a hard link called <em>LINKNAME<\/em> that points to the file <em>TARGETFILE<\/em>. Only works for files; if you try to do it with a folder, the error message &#8220;<strong>ln: `<em>\/folder\/name\/here<\/em>&#8216;: hard link not allowed for directory<\/strong>&#8220;.<\/li>\n<li><code><strong>ln -i <em>COMMAND<\/em><\/strong><\/code> &#8211; Runs ln interactive mode, where it will ask you before running the command <em>COMMAND<\/em>, where the COMMAND is one of the commands above.<\/li>\n<li><code><strong>ln -f <em>COMMAND<\/em><\/strong><\/code> &#8211; Forces ln to override any existing files while running the command <em>COMMAND<\/em>. For example, if you do <strong>ln -s \/bin file<\/strong> and currently <em>file<\/em> exists, you will get &#8220;<strong>ln: creating (symbolic\/hard) link `<em>linkname<\/em>&#8216;: File exists<\/strong>&#8220;. Use <span style=\"font-weight: bold;\">ln -f \/bin file<\/span> to make it work.<\/li>\n<li><span style=\"font-style: italic;\">(Windows only)<\/span> You remove fake symbolic links (shortcuts) with <code><strong>del <em>linkname<\/em>.lnk<\/strong><\/code> to accommodate the fact that it is a Windows shortcut. You can remove hard links the normal way you delete a file &#8211; <code><strong>del <em>hardlinkname<\/em><\/strong><\/code>.<\/li>\n<li><span style=\"font-style: italic;\">(Linux only)<\/span> You remove symbolic and hard links the regular way you would remove files &#8211; <code><span style=\"font-weight: bold;\">rm <span style=\"font-style: italic;\">yourlinkname<\/span><\/span><\/code>.<\/li>\n<\/ol>\n<p>If you found this article useful or helpful, please help <a href=\"\/\">Compdigitec<\/a> spread the word or please leave a comment. Don&#8217;t forget to <a href=\"\/labs\/feed\/\">subscribe<\/a> to Compdigitec Labs for more interesting articles!<\/p>","protected":false},"excerpt":{"rendered":"<p>Symbolic and hard links are a very convenient feature of the Linux and UNIX operating systems &#8211; they enable you to create a short alias, use it to avoid duplicate data and much, much more. They are also availible on Windows to a limited extent &#8211; NTFS supports only hard links while FAT\/FAT32\/VFAT supports neither. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,4],"tags":[100,102,103,101,98,99,106,104,105],"_links":{"self":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/29"}],"collection":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/comments?post=29"}],"version-history":[{"count":0,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/29\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/media?parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/categories?post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/tags?post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}