A file or folder is referenced via a link. In Linux, we see How to Create Symbolic Links in Linux? symbolic links are used to organize and manage files.


Learn How to Create Symbolic Links in Linux?

with the ln command by reading this manual.

  1. A Linux-running computer
  2. Access to the command line or terminal window (Activities > Search > type Terminal)
  3. A user account with root or sudo rights (optional) (needed to access certain protected files and directories).

Ln Command to Create Symbolic Links

Open a terminal window and type the following command to use the ln function:

  • ln [-sf] [source] [destination]
  • The ln command creates a hard link by default.
  • To build a soft (symbolic) link, use the -s option.
  • The program will be forced to overwrite an existing file if the -f option is used.
  • The file or directory is linked to is its source.
  • The destination specifies where the link will be saved; if this field is left empty, the symlink will be saved in the current working directory.

Make a symbolic connection, for instance, with:

  • test file.txt, link file.txt, and ln -s

This makes test file.txt the target of a symbolic link created by link file.txt.

Use the ls command to see if the symbolic has been created:

  • link file.txt, ls -l

Create a Symbolic Link to Linux Directory

A directory can be referred to through a symbolic link. Under Linux, the following steps must be followed:

  • stock photos /stock photos ln -s /mnt/external drive

In the home (/) directory, this example creates a symbolic link with the name stock photos. The external drive’s stock photos directory is the location of the link.

Overwrite Symbolic Links Using Force

One possible error message is shown in the image below:

The error message informs the user that a file with the name link file.txt already exists in the destination. To make the system overwrite the destination link, use the -f option:

  • test file.txt, link file.txt, and ln -sf

Link Removal or Removal

The link will no longer work if the original file is relocated, removed, or if it becomes inaccessible (for example, if a server goes offline). Use either the rm (removal) or unlink command to delete a symbolic link:

  • delete link file.txt

Disconnect link file.txt

Hard Links vs. Soft Links

A link can be made in one of two ways using the ln command:

  • Soft links
  • Hard links

1: Soft (Symbolic) Links

A soft link, also known as a symbolic link or symbolic, directs users to the path or location of the original file. On the internet, it operates much like a hyperlink.

How to Create Symbolic Links in Linux? Here are some crucial features of a soft link:

  1. The original data is still present even if the symbolic link file is removed.
  2. The symbolic link will not operate if the original file is moved or removed.
  3. A file on a different file system may be referenced using a soft link.
  4. To easily access a commonly used file without typing the complete location, soft links are widely utilized.

2: Hard Links

Several things occur when a file is saved to a hard drive:

  1. The disc receives a physical write of the data.
  2. In order to point to the location of the data, an internal reference file called inode is made.
  3. The inodes data is given a filename to be used as a reference.

A hard link operates by establishing a new filename that points to the original file’s inode information. In actuality, it’s comparable to making a copy of the file.

Here are some crucial characteristics of hard links:

  1. Other hard links allow access to the file data even if the original file is removed.
  2. Hard links still function even if the original file is moved.
  3. Only files located in the same file system can be referenced by a hard link.
  4. When there are no harder links, both the inode and the file data are permanently erased.


Now that you’ve learned about hard and symbolic (soft) links, you should be able to use them effectively. How to Create Symbolic Links in Linux? using the ln command, then use the ls tool to check them.