How to Create Symbolic Link in Linux (ln Command)
You can use the ln command to create links (shortcuts) to files and folders in Linux. The sections below explain how to do it with some examples.
Creating a Link for a File
To create a link to a file, open the terminal and type the following command.
Command :
ln -s [target file] [name for the link]
The command has these parts:
- The -s option tells ln to create a link. Without this option, it creates a different type of link called a âhard linkâ.
- [target file] is the file you want to link to.
- [name for the link] is the name you want to give the link file. If you leave this part out, the link will be created in the current folder.
For example, to create a link called âlink-file.txtâ that points to the file âtarget-file.txtâ in the âtestâ folder, type the below command.
Command :
ln -s test/target-file.txt link-file.txt
Output :
The command wonât show any output. But if you type ls, youâll see the new link file âlink-file.txtâ.
To see more details about the link file, you can type the below Command.
Command :
ls -l link-file.txt
Output :
The letter l at the start shows itâs a link file. The output also shows the path to the target file that the link points to.
How to Use ln Command to Create Symbolic Links in Linux
A symbolic link (symlink) is like a shortcut that points to a file or folder on Linux and other similar operating systems. Symlinks can be useful for organizing files and folders, or for making it easier to access files from different locations.
In this guide, youâll learn how to create symbolic links in Linux using the âlnâ command.
Use ln Command to Create Symbolic Links in Linux
- What Is a Symlink (Symbolic Link)?
- How to Create Symbolic Link in Linux (ln Command)
- Create Symlink for Directory
- Overwrite Symbolic Links
- Find Broken Symbolic Links
- Remove Symbolic Links