In Linux, a symbolic link (often called a symlink or soft link) is essentially a shortcut that points to another file or directory on your system. Unlike Windows shortcuts, symlinks operate at the filesystem level, meaning programs will interact with a symlink exactly as if it were the original file. This is incredibly useful for organizing files, managing software configurations, and redirecting data without duplicating it.
Using the ln Command
To create a symbolic link in the Linux terminal, you use the ln command combined with the -s (symbolic) flag.
The basic syntax is:ln -s [target_file] [link_name]
- target_file: The original file or directory you want to point to. It is highly recommended to use the absolute path (e.g.,
/var/www/html) to prevent broken links if you move the symlink later. - link_name: The name (and location) of the shortcut you are creating.
Example: Creating a Symlink to a File
Let’s say you have a configuration file located deep in your system at /etc/nginx/sites-available/mywebsite.conf, and you want a quick shortcut to it on your desktop.
You would open the terminal and type:ln -s /etc/nginx/sites-available/mywebsite.conf ~/Desktop/website-config
Now, if you open ~/Desktop/website-config in a text editor, you are actually editing the original file in the /etc directory.
How to Verify a Symbolic Link
To confirm that your symlink was created successfully and to see where it points, use the ls -l command.
ls -l ~/Desktop/website-config
The output will show an l at the beginning of the permissions block (indicating a link), and it will display an arrow pointing to the target:lrwxrwxrwx 1 user user 38 Aug 18 10:00 website-config -> /etc/nginx/sites-available/mywebsite.conf
How to Delete a Symbolic Link
If you no longer need the shortcut, you can delete it using the standard rm command just like any normal file.
rm ~/Desktop/website-config
Important: Removing the symbolic link will ONLY delete the shortcut. It will not delete the original target file or directory.