Home » Linux Command » Ln Command in Linux (Create Symbolic Links)

Ln Command in Linux (Create Symbolic Links)

Update on:
Oct 4, 2021

A symbolic hyperlink, often known as a symlink or smooth hyperlink, is a particular sort of file that factors to a different file or listing.

On this information, we are going to cowl how one can use the ln command to create symbolic hyperlinks.

Hyperlinks Varieties

There are two sorts of hyperlinks in Linux/UNIX techniques:

  • Onerous hyperlinks. You possibly can assume a tough hyperlink as a further title for an current file. Onerous hyperlinks are associating two or extra file names with the identical inode . You possibly can create a number of onerous hyperlinks for a single file. Onerous hyperlinks can’t be created for directories and recordsdata on a unique filesystem or partition.
  • Tender hyperlinks. A smooth hyperlink is one thing like a shortcut in Home windows. It’s an oblique pointer to a file or listing. Not like a tough hyperlink, a symbolic hyperlink can level to a file or a listing on a unique filesystem or partition.

Tips on how to Use the ln Command

ln is a command-line utility for creating hyperlinks between recordsdata. By default, the ln command creates onerous hyperlinks. To create a symbolic hyperlink, use the -s (--symbolic) choice.

The ln command syntax for creating symbolic hyperlinks is as follows:

  • If each the FILE and LINK are given, ln will create a hyperlink from the file specified as the primary argument (FILE) to the file specified because the second argument (LINK).
  • If just one file is given as an argument or the second argument is a dot (.), ln will create a hyperlink to that file within the present working listing . The title of the symlink would be the identical because the title of the file it factors to.

By default, on success, ln doesn’t produce any output and returns zero.

Creating Symlink To a File

To create a symbolic hyperlink to a given file, open your terminal and sort:

$ ln -s source_file symbolic_link

Exchange source_file with the title of the prevailing file for which you need to create the symbolic hyperlink and symbolic_link with the title of the symbolic hyperlink.

The symbolic_link parameter is optionally available. If you don’t specify the symbolic hyperlink, the ln command will create a brand new hyperlink in your present listing:

Within the following instance, we’re making a symbolic hyperlink named my_link.txt to a file named my_file.txt:

$ ln -s my_file.txt my_link.txt

To confirm that the symlink was efficiently created, use the ls command:

$ ls -l my_link.txt

The output will look one thing like this:

lrwxrwxrwx 1 linuxize customers  4 Nov  2 23:03  my_link.txt -> my_file.txt

The l character is a file sort flag that represents a symbolic hyperlink. The -> image exhibits the file the symlink factors to.

Creating Symlinks To a Listing

The command for making a symbolic hyperlink to a listing is identical as when making a symbolic hyperlink to a file. Specify the listing title as the primary parameter and the symlink because the second parameter.

For instance, if you wish to create a symbolic hyperlink from the /mnt/my_drive/films listing to the ~/my_movies listing you’ll run:

$ ln -s /mnt/my_drive/films ~/my_movies

Overwriting Symlinks

For those who attempt to create a symbolic hyperlink that already exists , the ln command will print an error message.

$ ln -s my_file.txt my_link.txt
ln: didn't create symbolic hyperlink 'my_link.txt': File exists

To overwrite the vacation spot path of the symlink, use the -f (--force) choice.

$ ln -sf my_file.txt my_link.txt

Eradicating Symlinks

To delete/take away symbolic hyperlinks use both the unlink or rm command.

The syntax of the unlink may be very easy:

unlink symlink_to_remove

Eradicating a symbolic hyperlink utilizing the rm command is identical as when eradicating a file:

rm symlink_to_remove

Regardless of which command you employ, when eradicating a symbolic hyperlink not append the / trailing slash on the finish of its title.

For those who delete or transfer the supply file to a unique location, the symbolic file shall be left dangling (damaged) and must be eliminated.


To create a symbolic hyperlink is Linux use the ln command with the -s choice.

For extra details about the ln command, go to the ln man web page or sort man ln in your terminal.

You probably have any questions or suggestions, be at liberty to go away a remark.

Related Posts

The 30 most useful Linux commands

This article will introduce some practical and common Linux or Unix command , which is the Linux system administrators normally use the command . This article is not a complete list, but a brief list of commands that can be useful...

15 Practical examples of tcpdump command

15 Practical examples of tcpdump command

The tcpdump is the most essential and powerful command-line network packet sniffing tool. We use it to analyze network packets, capture or filter TCP/IP packets that transferred and received over the network on a specific network interface. It is available in almost...

15 Useful “df” Commands to Check Disk Space in Linux

15 Useful “df” Commands to Check Disk Space in Linux

There are several Linux tools available on the internet to check disk space utilization; we can use any of them. But, Linux has a best built-in command-line utility called “df”. The “df” is the short form of “disk filesystem”, we can get detailed information on used...

15 Practical examples of echo command

15 Practical examples of echo command

If you are writing a bash script, you know echo command very well. It is use to display text lines on an output screen or a file. The echo command is the most common command used by all Linux users, and it is built-in Linux command. echo command syntax: echo...

Follow Us

Our Communities

More on Linux Command

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!



Submit a Comment

Your email address will not be published. Required fields are marked *

3 × 2 =