How to create symbolic links in Ubuntu 22.04

A symbolic link in Linux is similar to shortcuts in Microsoft Windows in that these symbolic links point to a different file in the Linux directory. There are two types of symbolic links, known as soft links and hard links.

Soft links simply point to another file or directory in Ubuntu’s file system with the same name and path, while hard links are created with some new names, just like copies of original files.

This blog explores the method of creating the symbolic links in Ubuntu using some simple examples.

How to create symbolic links in Ubuntu 22.04?

By default in Ubuntu, the ln utility is available, which associates files/folders with some other files. The ln command utility is used to create the symbolic links with the -s option. The general syntax for using the ln command:

$ ln -s [OPTIONS] FILE LINK

In the above expressions, the user is supposed to provide the two parameters, one from File whose symbolic link is to be created and the other link to which the file is to be linked. If the user does not provide the link, Ubuntu links the file to the current directory.

For better understanding, following the general syntax above, the symbolic link for the file “MyCFile” is created with the command:

$ ln -s MyCFile MyLink

List the contents of the directory to confirm the symbolic link:

$ ls -l My connection

In the above command, the “-l” option is used to show the link of the file.

How to create symbolic links in Ubuntu?

Creating the symbolic links of the directories is similar to creating links of files. For example, we create the symbolic link from /Home/Music to ~/my_music:

$ ln -s /home/music ~/my music

How to remove symbolic links in Ubuntu 22.04?

There are two options, either delete the symbolic link or unlink the symbolic link. To unlink a file from its symbolic link, use the command:

$ delete link ~/my music

If you want to remove the symbolic link, run the following command:

$ rm My connection

The link has been deleted by Ubuntu.

Conclusion

The ln command utility with the -s option is used to create symbolic links of files and directories in Ubuntu 22.04. In this blog, different creations of symbolic links have been explored with some examples.

Related Posts