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 0 Comments

Grub Vs Lilo

A system requires different programs for accomplishing different tasks. The boot loader is the first program that runs when a computer starts. It is responsible for loading and transferring control

How To 0 Comments

How To Find IP Address From Domain Name In Linux/Unix?

This post was last updated on August 1st, 2020 at 03:35 pmBefore we start running a command to find the IP addresses from the domain name. First, we will discuss

Linux Topics 0 Comments

How To Split A Large File Into Multiple Smaller Files In Linux/Unix?

This post was last updated on August 1st, 2020 at 12:32 pmSuppose you have an archive file of size more than 5GB, and if you want to burn it on

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply