In this article, a detailed demonstration to create symbolic links on Manjaro is provided.
Difference between Soft links and Hard links?
The hard links in Linux are nonetheless a copy(mirror) of a file and can access the original fileâs content. Whereas the soft link just contains a link to the original(parent) file. Soft links are also referred to as symbolic links and these links only point towards a file rather than containing its data. If the original file of the hard link is deleted, the hard link can be accessed even then. However, if the original file of the soft link is removed/displaced, the soft link will be broken and will not be useful anymore.
How to create symbolic links in Manjaro
This section contains a step-by-step guide to creating symbolic links on Manjaro Linux. We start this guide with a basic intro of the ln command that creates symbolic links in Linux. The ln is a Linux-based command used to create symbolic(soft) links. The syntax of the command is written below.
The ln command in Manjaro is used to create symlinks(soft links). It is noticed that the ln command creates a by default, but soft links can be created using the -s option of the ln command. Moreover, the target–file entity in the syntax above refers to the fileâs path for creating a symbolic link, whereas the symlink-file represents the symbolic link file.
How to create symbolic link for a file using the ln command
We have a text file named linuxhint.txt that is placed in our Desktop directory. The command provided creates a link to the linuxhint.txt file inside a file named symfile.txt.
And to verify that the link is created or not, use the ls command with -l flag as shown below. For the output, it is observed that the symfile.txt directs to the file named linuxhint.txt.
How to create a symbolic link for a directory in Manjaro
As described earlier, symlinks can be created for files and directories.
Let’s say there is a directory named linux that resides in the desktop directory. In the below-mentioned command, the sym_dir directory is created to store symbolic link to the linux directory.
You can verify the creation of a link by issuing the following command.
How to overwrite the symbolic link
Let’s try to create a symbolic link to a file named “staff.txt” , and here we are using the symbolic link file named “symfile.txt” (already exists). By doing so, you will encounter the following error.
The output of the above command shows that you are unable to overwrite the existing file. To do so, you must use the f with -s flag to overwrite the existing symbolic link file. The command written below assists us in this regard.
And if we use ls command, you will observe that the symfile.txt is now pointing towards staff.txt.
How to find broken symbolic links
If the location of the target file is changed or the file is deleted, then the symbolic link associated with it is referred to as a broken link. The below-stated command can be exercised to find the broken links. The output contains two .txt files that means these files contain broken links.
How to remove or unlink the symbolic links
If the original file is moved/deleted, you have the following possibilities.
– Either remove the symbolic link file, and the command written below will remove symfile.txt file:
– Or unlink the symbolic file using the unlink command. In our case, the below-mentioned command unlinks the symbolic link created for the linux directory.
Conclusion
In Linux-based systems, a symbolic link refers to opening the file by creating a soft link to that file. The symlinks can be created by exercising the âlnâ command in Manjaro. This descriptive post provides the demonstration of the ln command to create symbolic links in Manjaro Linux. By default, it creates hard links, but it can be used with a -s flag to generate a symbolic link. You can also overwrite the symbolic link file by creating another symbolic link on the same file. Moreover, if the symbolic link is useless, then link files can be removed, or the symbolic link can be unlinked. This guide also provides the difference between hard and soft links (symbolic links) for a better understanding.