<\/span><\/h2>\n\n\n\nCreating symbolic link in Linux is a straightforward process with the command ln -s and both paths from the source and destination directory.<\/p>\n\n\n\n
ln -s \/path\/to\/source\/file \/path\/to\/destination\/file<\/p>\n\n\n\n
You can find an example below for Nginx site configurations:<\/p>\n\n\n\n
ln -s \/etc\/nginx\/sites-available\/my.site.conf \/etc\/nginx\/sites-enabled\/my.site.conf<\/code><\/pre>\n\n\n\nYou can try creating your own symbolic link in the opt directory, for example:<\/p>\n\n\n\n
root@Server:\/opt# ln -s \/etc\/someconfig.conf someconfig.conf<\/code><\/pre>\n\n\n\nUnlike hard links, symlink will have its own inode number that will refer to the path of the original file. You can check the symbolic link that was created with the command:<\/p>\n\n\n\n
# ls -l\nsomeconf.conf -> \/etc\/someconf.conf<\/code><\/pre>\n\n\n\nYou can notice that this shows that the someconf.conf file is a symbolic link to \/etc\/someconf.conf file.<\/p>\n\n\n\n
If you try to create a symlink that already exists, you will receive an error that the file already exists. You can run ln -sf <\/strong>to force the creation of symlink, which will unlink and create the symbolic link again with a different path:<\/p>\n\n\n\n# ln -sf \/etc\/new\/app\/someconf.conf someconf.conf<\/code><\/pre>\n\n\n\n<\/span>How to remove a symlink<\/span><\/h2>\n\n\n\nThere are two ways to remove the created symlinks, you can either use the rm <\/strong>command or unlink<\/strong>. To delete the symlink that was created previously with rm or unlink, you can use: <\/p>\n\n\n\nrm someconf.conf <\/code><\/pre>\n\n\n\nor <\/p>\n\n\n\n
unlink someconf.conf<\/code><\/pre>\n\n\n\nBoth will have the same effect, it will remove the someconf.conf symlink but keep the file in the source directory \/etc\/someconf.conf.<\/p>\n\n\n\n
Previously, we mentioned Chains of Symlinks, which are symlinks of symlink. Let\u2019s say you have the previous symbolic link. Then, you create a new symlink of that file.<\/p>\n\n\n\n
ln -s \/etc\/someconf.conf \/opt\/someconf.conf\nln -s \/opt\/someconf.conf \/var\/opt\/someconf.conf<\/code><\/pre>\n\n\n\nNow, if you try to delete the last symlink, the head of the chain with:<\/p>\n\n\n\n
unlink \/var\/opt\/someconf.conf <\/code><\/pre>\n\n\n\nThis will remove the symlink someconf.conf -> \/opt\/someconf.conf<\/strong>, but the symlink in \/opt\/someconf.conf<\/strong> will still exist. This does not apply if you delete the \/opt\/someconf.conf<\/strong> symlink instead of \/var\/opt\/someconf.conf, then the symbolic link chain won\u2019t exist.<\/p>\n\n\n\n