{"id":22203,"date":"2023-10-01T16:41:38","date_gmt":"2023-10-01T16:41:38","guid":{"rendered":"https:\/\/linuxways.net\/?p=22203"},"modified":"2023-10-01T16:41:38","modified_gmt":"2023-10-01T16:41:38","slug":"how-to-create-a-soft-or-symbolic-link-in-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-create-a-soft-or-symbolic-link-in-ubuntu-22-04\/","title":{"rendered":"How to Create a Soft or Symbolic Link in Ubuntu 22.04?"},"content":{"rendered":"<p>A <strong>symbolic link<\/strong> also referred to as a <strong>soft link<\/strong> or <strong>symlink<\/strong> in Linux\/Ubuntu is similar to shortcuts in Microsoft Windows. A user can utilize a symbolic link to create shortcuts, i.e., a Symbolic link is a file that points to a source file\/directory.<\/p>\n<p>This article will demonstrate the creation of a symbolic link on Ubuntu 22.04 LTS. This article will discuss:<\/p>\n<ul>\n<li>How to Create\/Generate a Symbolic Link for a File in Linux\/Ubuntu?<\/li>\n<li>How to Create\/Generate a Symbolic Link for a Folder\/Directory in Linux\/Ubuntu?<\/li>\n<li>How to View a Symbolic Link\u2019s Target in Linux\/Ubuntu?<\/li>\n<li>How to Overwrite\/Rewrite a Symbolic Link in Linux\/Ubuntu?<\/li>\n<li>How to Remove\/Delete a Symbolic Link in Linux\/Ubuntu?<\/li>\n<\/ul>\n<h2><a id=\"post-22203-_9lx1tsu66cyv\"><\/a>How to Create\/Generate a Symbolic Link for a File in Linux\/Ubuntu?<\/h2>\n<p>In this section, a symbolic link for a file will be created. The syntax for creating a symbolic link is:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ln<\/span> <span class=\"re5\">-s<\/span> <span class=\"br0\">&#91;<\/span>Source_File_Name<span class=\"br0\">&#93;<\/span> <span class=\"br0\">&#91;<\/span>Symbolic_Link_Name<span class=\"br0\">&#93;<\/span><\/div><\/div>\n<p>Where,<\/p>\n<ul>\n<li>ln: command for creating symbolic link<\/li>\n<li>s: symbolic link flag to create a soft link.<\/li>\n<\/ul>\n<p>Using the above syntax, a symbolic link for a file \u201c5g.txt\u201d can be created by executing the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ln<\/span> <span class=\"re5\">-s<\/span> 5g.txt 5glink<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1188\" class=\"wp-image-22214\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-1.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-1-300x174.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-1-1024x594.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-1-768x446.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-1-1536x891.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above terminal, it can be verified that the symbolic link is created successfully. Additionally, the creation of the symbolic links can be verified by using Ubuntu UI:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1864\" height=\"1102\" class=\"wp-image-22216\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-2.png 1864w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-2-300x177.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-2-1024x605.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-2-768x454.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-2-1536x908.png 1536w\" sizes=\"auto, (max-width: 1864px) 100vw, 1864px\" \/><\/p>\n<h1><\/h1>\n<h2><a id=\"post-22203-_vwi4ezl9toa3\"><\/a>How to Create\/Generate a Symbolic Link for a Folder\/Directory in Linux\/Ubuntu?<\/h2>\n<p>In this section, a symbolic link for a directory will be created. The syntax for creating a symbolic link is:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ln<\/span> <span class=\"re5\">-s<\/span> <span class=\"br0\">&#91;<\/span>Source_Directory_Path<span class=\"br0\">&#93;<\/span> <span class=\"br0\">&#91;<\/span>Symbolic_Link_Destination_Path<span class=\"br0\">&#93;<\/span><\/div><\/div>\n<p>Where,<\/p>\n<ul>\n<li>ln: command for creating the symbolic link<\/li>\n<li>s: symbolic link flag to create a soft link.<\/li>\n<\/ul>\n<p>Using the above syntax, a symbolic link for a dictionary \u201cOthers\u201d can be created in the \u201cDownloads\u201d directory by executing the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ln<\/span> <span class=\"re5\">-s<\/span> <span class=\"sy0\">\/<\/span>home<span class=\"sy0\">\/<\/span>linuxuser<span class=\"sy0\">\/<\/span>Documents<span class=\"sy0\">\/<\/span>Others <span class=\"sy0\">\/<\/span>home<span class=\"sy0\">\/<\/span>linuxuser<span class=\"sy0\">\/<\/span>Downloads<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"657\" class=\"wp-image-22220\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-3.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-3-300x96.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-3-1024x329.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-3-768x246.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-3-1536x493.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be verified using the \u201c<strong>ls<\/strong>\u201d command in the Terminal that the symbolic link is created successfully in the \u201cDownloads\u201d directory. Additionally, the creation of a symbolic link can be verified by accessing the \u201cDownloads\u201d directory using Ubuntu UI:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1864\" height=\"1098\" class=\"wp-image-22223\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-4.png 1864w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-4-300x177.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-4-1024x603.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-4-768x452.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-4-1536x905.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-4-1020x600.png 1020w\" sizes=\"auto, (max-width: 1864px) 100vw, 1864px\" \/><\/p>\n<h2><a id=\"post-22203-_8kvuxx96z1hy\"><\/a>How to View a Symbolic Link\u2019s Target in Linux\/Ubuntu?<\/h2>\n<p>The <strong>target<\/strong>, i.e., the file or the directory that the symbolic link is pointing to, can be viewed by using the \u201c<strong>-l<\/strong>\u201d flag along with the <strong>list(ls) <\/strong>command, which lists the files in long format. For example, the target of the \u201cOthers\u201d symbolic link can be viewed by:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ls<\/span> <span class=\"re5\">-l<\/span><\/div><\/div>\n<h1><a id=\"post-22203-_h4mbtuqbyq71\"><\/a><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"507\" class=\"wp-image-22229\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-5.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-5-300x74.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-5-1024x254.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-5-768x190.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-5-1536x380.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/h1>\n<p>From the above image, it can be seen that the target of the \u201cOthers\u201d directory is \u201c\/home\/linuxuser\/Documents\/Others\u201d.<\/p>\n<h2><a id=\"post-22203-_yt3piu86zpyn\"><\/a>How to Overwrite\/Rewrite a Symbolic Link in Linux\/Ubuntu?<\/h2>\n<p>In case, a symbolic link of a file or a directory exists and we need to overwrite a symbol link, using the usual command, i.e., \u201cln -sf 5g.txt 5glink\u201d for overwriting a symbolic link for 5g.txt file will result in an error <strong>\u201cln: failed to create symbolic link \u20185glink\u2019: File exists<\/strong>\u201d. This error can be bypassed by adding the \u201c<strong>-f<\/strong>\u201d flag following the \u201c<strong>-s<\/strong>\u201d flag as shown below:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ln<\/span> <span class=\"re5\">-sf<\/span> 5g.txt 5glink<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"489\" class=\"wp-image-22240\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-6.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-6-300x72.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-6-1024x245.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-6-768x183.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-6-1536x367.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be seen that the symbolic link \u201c5glink\u201d is successfully overwritten.<\/p>\n<h1><\/h1>\n<h2><a id=\"post-22203-_o4ml7a8bq04\"><\/a>How to Remove\/Delete a Symbolic Link in Linux\/Ubuntu?<\/h2>\n<p>In case, we would like to remove the symbolic link because we don&#8217;t need it or if the source of the symbolic link is moved to another location, we can do that with either the \u201c<strong>rm<\/strong>\u201d or \u201c<strong>unlink<\/strong>\u201d command. To remove a symbolic link, we can run the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">rm<\/span> 5glink<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"427\" class=\"wp-image-22253\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-7.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-7-300x63.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-7-1024x214.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-7-768x160.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-7-1536x320.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the image above, it can be verified that the symbolic link is removed. Alternatively, the following command is used to remove a symbolic link using unlink:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">unlink<\/span> 5glink<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"490\" class=\"wp-image-22258\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-8.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-8-300x72.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-8-1024x245.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-8-768x184.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-22203-8-1536x368.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the image above, it can be verified that the symbolic link is removed.<\/p>\n<h1><\/h1>\n<h2><a id=\"post-22203-_k4r3ojha6hv3\"><\/a>Conclusion<\/h2>\n<p>Symbolic links for files and directories are created by using the \u201c<strong>ln<\/strong>\u201d command with the \u201c<strong>-s<\/strong>\u201d flag where \u201c-s\u201d represents the symbolic link flag to create a soft link. This article has demonstrated how to create, view, overwrite, and delete a symbolic link on Ubuntu 22.04 LTS.<\/p>","protected":false},"excerpt":{"rendered":"<p>Symbolic links for files and directories are created by using \u201cln\u201d command with \u201c-s\u201d flag, where -s represents the symbolic link flag to create a soft link.<\/p>","protected":false},"author":110,"featured_media":22330,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-22203","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=22203"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22203\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/22330"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=22203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=22203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=22203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}