ln command in Linux with Examples | Linux Command in Hindi | shortcut in linux by Mr coder rohit

Ln Command in Linux (Create Symbolic Links)




Watch this Video and Subscribe for Hindi 

click here 👇




A symbolic link, also known as a symlink or soft link, is a special type of file that points to another file or directory.

In this guide, we will cover how to use the ln command to create symbolic links.

There are two types of links in Linux/UNIX systems:

  • Hard links. You can think a hard link as an additional name for an existing file. Hard links are associating two or more file names with the same inode . You can create one or more hard links for a single file. Hard links cannot be created for directories and files on a different filesystem or partition.
  • Soft links. A soft link is something like a shortcut in Windows. It is an indirect pointer to a file or directory. Unlike a hard link, a symbolic link can point to a file or a directory on a different filesystem or partition.

How to Use the ln Command

ln is a command-line utility for creating links between files. By default, the ln command creates hard links. To create a symbolic link, use the -s (--symbolic) option.

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

ln -s [OPTIONS] FILE LINK
  • If both the FILE and LINK are given, ln will create a link from the file specified as the first argument (FILE) to the file specified as the second argument (LINK).
  • If only one file is given as an argument or the second argument is a dot (.), ln will create a link to that file in the current working directory . The name of the symlink will be the same as the name of the file it points to.

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

To create a symbolic link to a given file, open your terminal and type:

ln -s source_file symbolic_link

Replace source_file with the name of the existing file for which you want to create the symbolic link and symbolic_link with the name of the symbolic link.

The symbolic_link parameter is optional. If you do not specify the symbolic link, the ln command will create a new link in your current directory:

In the following example, we are creating a symbolic link named my_link.txt to a file named my_file.txt:

ln -s my_file.txt my_link.txt

To verify that the symlink was successfully created, use the ls command:

ls -l my_link.txt

The output will look something like this:

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

The l character is a file type flag that represents a symbolic link. The -> symbol shows the file the symlink points to.



Please Share

It Looks like you have completed your course!! We have created Online series based on the above content. You can give a test and check your skill.




Be a Part of CollegeSpike by giving your precious comment here and help us in improving our content.