How to Create a Symbolic Link in Linux

When organizing files in a graphical operating system like Windows, you often use “Shortcuts”—small icons on your desktop that, when clicked, immediately open a file buried deep inside your hard drive. In the Linux environment, the equivalent of a shortcut is called a Symbolic Link (often abbreviated as “symlink”).

However, symlinks are far more powerful than simple Windows shortcuts. To the Linux operating system, a symlink doesn’t just point to a file; it acts as if it is the file. If you have a massive configuration file hidden deep in /etc/nginx/sites-available/ and you create a symlink to it on your desktop, any program that opens the desktop link will seamlessly edit the original file without ever knowing it was redirected.

Creating these powerful links requires a single, simple terminal command: ln.

How to Create a Symbolic Link

To create a symlink, you use the ln (link) command combined with the -s (symbolic) flag. If you forget the -s flag, Linux will create a “Hard Link,” which is a completely different (and much more complex) type of file association.

The syntax for the command is always the same: first you state the existing file, and then you state where you want the new link to go.

ln -s /path/to/original_file.txt /path/to/new_symlink.txt

A Practical Example

Imagine you have a very important log file located at /var/log/apache2/error.log. You are tired of typing that long path every time you want to check your server errors. You want a shortcut placed directly in your home directory, and you want to name the shortcut my_errors.log.

  1. Open your terminal application.
  2. Type the following command and press Enter:

ln -s /var/log/apache2/error.log ~/my_errors.log

You have now created the symlink. If you open my_errors.log in your home directory, you will see the exact contents of the Apache error log. If you delete text from the symlink, that text is instantly deleted from the real Apache log.

How to Verify a Symlink

If you are looking at a directory full of files, how can you tell which ones are real files and which ones are just symbolic links?

You can use the list command (ls) with the long-format flag (-l).

ls -l

When the terminal prints the contents of the directory, you will see two clear indicators if a file is a symlink:

  1. The very first character on the line (before the read/write permissions) will be a lowercase l (for link).
  2. At the end of the line, the filename will have an arrow physically pointing to its original source file (e.g., my_errors.log -> /var/log/apache2/error.log).

How to Delete a Symlink (Safely)

Because a symlink acts exactly like the original file, many beginners are terrified to delete them, fearing that deleting the link will accidentally delete the precious original file.

You do not need to worry. Deleting a symbolic link only deletes the shortcut itself. The original file remains completely untouched and safe.

To delete a symlink, simply use the standard rm (remove) command, exactly as you would with any normal file:

rm ~/my_errors.log

The shortcut is gone, but the original Apache error log in the /var/log directory is perfectly fine.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.