Windows users are used to being able to create shortcuts to have fast access to their files and folders easily. This is especially useful when these are buried deep in their filesystem. This feature isn't as obvious on most Linux systems as it is on Windows.
In this guide, I'll show you how to create a shortcut on a Unix-like operating system using a symlink.
Create Symlink in Linux
Terminal way (the link will appear in the folder the terminal points to):
Syntax:
ln -s <target file or folder> <link name - which can be a file or folder>
Example:
ln -s /folderorfile/link/will/point/to /name/of/the/link
Desktop way:
To create a symlink without a terminal, just hold Shift+Ctrl and drag the file or folder you want to link to to the location where you want the shortcut. This method may not work with all desktop managers.
Linux Symlink Frequently Asked Questions
What is a symbolic link in Linux?
A symbolic link, often called a symlink, is a type of file in Linux that points to another file or directory. It's similar to a shortcut in Windows, allowing quick access to the linked resource.
What's the difference between a hard link and a symbolic link?
A hard link is a direct reference to the data on the disk, acting as a mirror copy, whereas a symbolic link is just a pointer to another file or directory. Deleting the original file affects hard links but not symbolic links.
Can symbolic links point to a network location or external drive?
Symbolic links can point to resources on a network location or an external drive. However, the link will not work if the target is not accessible.
How do I view symbolic links in a directory?
Use the:
ls -l
command in a directory. Symbolic links will be displayed with an arrow (`->`) showing the link path.
What happens to a symbolic link if the original file is moved or deleted?
If the original file is moved, the symbolic link will be broken and will not work until the original file is restored or the link is updated. If the original file is deleted, the link will remain but point to a non-existing location.
How do I remove a symbolic link without affecting the original file?
Use the rm command followed by the symlink name. This will remove the symlink but not the file or directory it points to.
Is it possible to create a symbolic link to a symbolic link?
You can create a symbolic link that points to another symbolic link. The system will resolve the chain of links to access the final target file or directory.
How can I find all symbolic links in a directory?
Use the find command with the -type l option. For example:
find /path/to/dir -type l
This command will list all symbolic links in the directory /path/to/dir.
Can I create a symbolic link to a directory?
Symbolic links can point to directories as well as files. The command is the same:
ln -s [TARGET_DIRECTORY] [LINK_NAME]