Linux allows you to create symbolic links, or symlinks, that point to another file or folder on your machine. The best way to do this is with the
ln terminal command—though there are some graphical file managers that can create symbolic links too.
What Are Symbolic Links?
Symbolic links are basically advanced shortcuts. A symbolic link you create will appear to be the same as the original file or folder it’s pointing at, even though it’s just a link.
For example, let’s say you have a program that needs its files stored at /home/user/.program. But you want to store those files on another partition, which is mounted at /mnt/partition. You can move the .program directory to /mnt/partition/.program, and then create a symbolic link at /home/user/.program pointing to /mnt/partition/.program. The program will try to access its folder at /home/user/.program, and the operating system will redirect it to /mnt/partition/.program.
This is entirely transparent to the operating system and the programs you use. If you browse to the /home/user/.program directory in a file manager, it will appear to contain the files inside /mnt/partition/.program.
In addition to “symbolic links”, also known as “soft links”, you can instead create a “hard link”. A symbolic or soft link points to a path in the file system. For example, let’s say you have a symbolic (or “soft”) link from /home/examplefile pointing to /var/examplefile. If you move the file at /var/examplefile, the link at /home/examplefile will be broken. However, if you create a “hard link”, it will actually point to the underlying inode on the file system. So, if you created a hard link from /home/examplefile pointing to /var/examplefile and later moved /var/examplefile, the link at /home/examplefile would still point to the file, no matter where you moved it to. The hard link works at a lower level.
You should generally use standard symbolic links, also known as “soft links”, if you’re not sure which to use.
How to Create Symbolic Links with ln
To create a symbolic link with the ln command, you’ll first need to open a terminal window. Once you have, run the ln command in the following form:
ln -s /path/to/original /path/to/link
You can specify either a path to a directory or file in the command. It will “just work”, whatever you enter.
So, if you wanted to create a symbolic link of your Downloads folder located on your Desktop, you’d run the following command:
ln -s /home/name/Downloads /home/name/Desktop
-s in the command creates a symbolic link. If you wanted to create a hard link instead—again, this is something you usually wouldn’t want to do unless you have a specific reason to do so—you’d exclude the
-s from the command.
Using our example, if we look inside our Desktop folder, we find a “Downloads” folder that appears to contain all the same files as our main Downloads folder.
How to Delete Symbolic Links
To remove symbolic links, you can just delete them normally. For example, you could right-click them and delete them using a graphical file manager, or use the following command, which is used to delete (or “remove”) any type of file:
How to Create Symbolic Links with a Graphical Tool
Many Linux file managers offer the ability to create symbolic links graphically. If yours does, you can generally do this by right-clicking a folder or file and selecting “Copy”, and then right-clicking inside another folder and selecting “Make Link”, “Paste as Link”, or a similarly named option.
The Nautilus file manager included with GNOME and Ubuntu’s Unity desktops doesn’t have this menu option anymore, but it does have a shortcut that’ll do the same thing. To create a symbolic link in Nautilus, press and hold the Ctrl and Shift keys on your keyboard. Drag and drop a file or folder to another location. Nautilus will create a symbolic link to the original file or folder at the location you drop the file or folder rather than moving the original file or folder.
- › How to Create and Use Symbolic Links (Symlinks) on a Mac
- › How to Make a Shortcut (Alias) to a File or Folder on a Mac
- › How to Install Google and Microsoft Fonts on Linux
- › How to View a List of Symbolic Links on Windows 11
- › How to Use the stat Command on Linux
- › How to Mount Removable Drives and Network Locations in the Windows Subsystem for Linux
- › How to Check If a File Exists in Linux Bash Scripts
- › Will iOS 17 and iPadOS Run on my iPhone or iPad?