How to create Symbolic Links in Manjaro

Symbolic links (also known as soft links) are the links that refer to some files or directories in Linux systems. The original file and symlink file are semi-dependent on each other. For instance, if the symlink file is deleted, it would have no effect on the parent file. However, if the parent file is moved/deleted, it breaks the symbolic links. One can associate its importance as shortcuts where you can just open an application by clicking on the shortcut icon.

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.

$ ln -s [path-of-target-file] [path-of-symlink-file]

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 targetfile 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.

$ ln -s linuxhint.txt 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.

$ ls -l symfile.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.

$ ln -s linux sym_dir

A picture containing logo Description automatically generated

You can verify the creation of a link by issuing the following command.

$ ls -l sym_dir

Text Description automatically generated

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.

$ ln -s staff.txt symfile.txt

Text Description automatically generated with medium confidence

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.

$ ln -sf staff.txt symfile.txt

Text Description automatically generated with medium confidence

And if we use ls command, you will observe that the symfile.txt is now pointing towards staff.txt.

$ ls -l symfile.txt

Text Description automatically generated with medium confidence

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.

$ find -xtype l

A screenshot of a computer Description automatically generated with medium confidence

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:

$ rm symfile.txt

A picture containing logo Description automatically generated

– 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.

$ unlink sym_dir

Text Description automatically generated

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.



from https://ift.tt/3InAAHa

Post a Comment

0 Comments