What are symlinks and how to create them in Linux?
 

What are symlinks and how to create them in Linux?

 

Symbolic links also known as symlinks or soft links are special types of files that point to another file or directory in the filesystem. These are very much similar to the shortcuts used in Windows.

Symlinks are very useful these have the ability to create links to file or directories on a remote computer connected using NFS. The hard links do not possess such capabilities.

Here we will discuss how to create a symlink on Linux or Unix system.

Types of links in Linux or Unix

In general terms, a link basically represents the connections between two things similarly in Linux a link is a pointer that points to a file or directory.

In Linux, links can be categorized into two types –

1. Hard link –

If you create a hard link to a file or directory the created link will be the same as the original one. Each hard link shares the same index node value. A hard link retains its value after deleting the original file or directory.

2. Soft link –

A soft link is very much like a shortcut of a file or directory in the file system. Symlinks are dangling when you delete the original file the all symlinks created to that file will be broken.

For instance, suppose you have created a hard link name test_hlink and a soft link called test_slink to testfile.txt file. Now when you delete testfile.txt the content of test_hlink will still exist and when you click on test_slink it will display a message saying the link is broken.

How to create a hard link using the ln command

Linux or Unix provides ln command to create a hard or soft link by default it creates a hard link. The syntax of the ln command is given below –

ln [Option][Orignal file or directory name][Link name]

To create a hard link use the following command-

ln source_file_or_directory link_name

For example –

ln testfile.txt test_hlink

A hard link with the name test_hlink will be created to the file testfile.txt.

How to create a symbolic link using the ln command

For creating a symbolic link to the source file you need to use -s option with the ln command. The syntax and example are given below-

ln -s source_file_or_directory link_name

For example –

ln -s testfile.txt test_slink

Once this command executes a shortcut or link of testfile.txt will be created now see the image below.

If you want to know more about the usage of the ln command then see its manual page in your terminal by using –

man ln

Conclusion

Now you know what is a symlink or hard link and how to create them. If you have a query then leave it in the comments below.

Previous [ubuntu] USB Harddrive versus USB keyboard.
Next Using pwd command in Linux
 

About author

You might also like

Linux Topics 1Comments

How To Add/Remove A Software Repository In Linux?

This post was last updated on August 3rd, 2020 at 02:56 pmContents1 Software Repository2 Adding a repository in debian based systems3 Remove repository in Debian based systems4 Adding a repository

Linux Topics 0 Comments

How To Install Cockpit Web Console On CentOS 8?

The cockpit is a web console that makes it easy to administer the GNU/Linux server. It has a user-friendly web-based interface that enables you to carry out different system admin

Linux Topics 0 Comments

How To Setup FTP Server In Linux/Unix?

This post was last updated on August 2nd, 2020 at 08:10 pmFTP is the short form of File Transfer Protocol. It is a standard networking protocol used to transfer files

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply