In this article we are going to shows how to use ln command in Linux. If you want to learn about ln command in Linux with Examples then this post is ideal for you.
In the Linux, the ln is a command utility that is used to create hard link or a symbolic link (symlink or soft link) between files. A symbolic link (symlink or soft link) is a type of file that points to another file or directory.
Linux is an operating system, similar like Windows OS, iOS, and Mac OS. Linux is one of the most popular operating system on the planet, Android is also powered by Linux OS(operating system).
Linux OS(operating system) is also distributed under an open source license. Open source following these points :
- Freely to run the program, for any purpose.
- Free to study how the program works.
- Freely to re-distribute copies so you can help your friends.
- Free to distribute copies of your modified versions to others.
How to use Ln Command in Linux
As we know, ln
command is used to create links between files. By default, it creates hard links. If you wants create a symbolic link, use the -s
(--symbolic
) option with ln
command:
In the Linux, the basic syntax of the ln command is show as below:
ln -s [OPTIONS] FILE LINK
Creating Symlink to a File
To create symlink to a file, run the command as show below:
ln -s source_file symbolic_link
In the command above, 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.
If you do not pass the symbolic link in the ln
command, it will create a new link in your current directory:
ln -s /home/file.txt file_link.txt
Creating Symlink to a Directory
To creating symlink to a directory just pass the source directory as first argument and symlink as second argument as show below.
For an example, if you want to create a symbolic link for /etc/nginx/sites-available/example.com
to the /etc/nginx/sites-enabled/
directory, run the command below:
ln -s /drive/my_collection/songs ~/my_songs
Overwriting Symlink
If a symbolic link is already exists in your system and you try to create it again then the ln
command will display an error message as show below:
ln -s /home/file.txt file_link.txt
Output
ln: failed to create symbolic link 'file_link.txt': File exists
Use -f
(--force
) option, if you want to overwrite the symlink:
ln -sf /home/file.txt file_link.txt
Deleting Symlink
To delete or remove symlinks, use unlink
or rm
command as show below:
unlink name_of_symlink
OR
rm symlink_to_remove
That’s all.
If you face any error and issue in above steps , please use comment box below to report.
If our tutorials helped you, please consider buying us a coffee. We appreciate your support!
Thank you for your support.