What a symlink is and why you'd use one

A symlink (short for symbolic link) is a pointer to a file or folder that lives somewhere else on your system. When you open a symlink, Linux takes you to the actual file instead. The symlink itself takes almost no space — it's just a reference, like a shortcut on Windows or macOS.

Symlinks solve a real problem: you have a file in one location, but you need it to appear in another location too, without making a copy. If you edit the file through the symlink, the original changes. If you edit the original, the symlink shows the updated version. They stay in sync because they're the same file.

Common reasons to use symlinks: keeping your Downloads folder organized by moving files into category folders but still seeing them in one place; linking a config file from a program's folder into your home directory where you actually edit it; or pointing to a large media library stored on an external drive so it appears in your home folder.

Key Takeaways

  • Create a symlink with ln -s /path/to/original /path/to/symlink, where the original path comes first and the symlink path comes second.
  • The original file must exist before you create the symlink, and the symlink will break if you move or delete the original.
  • Use absolute paths (starting with /) when creating symlinks so they work no matter which folder you're in.
  • Remove a symlink with rm /path/to/symlink — this deletes only the link, not the original file.
  • Check if a file is a symlink and see where it points by running ls -l and looking for an arrow (->) in the output.

The basic command: ln -s

The command to create a symlink is ln -s, where ln stands for "link" and -s means "symbolic." The structure is always the same: ln -s /path/to/original /path/to/symlink.

The original file path comes first. The symlink path comes second — this is where you want the link to appear. If you get them backwards, the command will fail or create a link pointing to the wrong thing.

Open a terminal and navigate to the folder where you want the symlink to live, or use the full path. Here's a real example: if you have a document at /home/username/Documents/ProjectA/report.pdf and you want a link to it in your Desktop folder, you would type:

ln -s /home/username/Documents/ProjectA/report.pdf /home/username/Desktop/report.pdf

Press Enter. If the command returns no message, it worked. The symlink now appears in your Desktop folder.

Using absolute paths so symlinks don't break

Always use absolute paths — paths that start with a forward slash and show the complete route from the root of your system. Absolute paths work the same way no matter which folder you're currently in.

The alternative is a relative path, which describes where the original is relative to where the symlink sits. Relative paths are shorter to type, but if you move the symlink to a different folder later, the link breaks because the relative distance changes.

To find the absolute path of a file, navigate to its folder in the terminal and type pwd (print working directory). This shows the full path. Then add the filename to the end. For example, if pwd returns /home/username/Documents and the file is named notes.txt, the absolute path is /home/username/Documents/notes.txt.

Use that full path in your ln -s command. This way, if you later move the symlink itself to a different folder, it still points to the right place.

Creating symlinks to folders

Symlinks work on folders the same way they work on files. The command is identical: ln -s /path/to/original/folder /path/to/symlink.

A practical example: you have a large photo library stored on an external hard drive at /media/username/external_drive/Photos, and you want it to appear in your home folder so you can access it quickly. You would type:

ln -s /media/username/external_drive/Photos /home/username/Photos

Now when you open your home folder, you see a Photos folder. Click into it and you're actually browsing the external drive. If you add new photos to the external drive, they appear in the symlink when ready.

One important difference from files: if you delete a symlink to a folder, only the link is removed, not the folder itself or anything inside it. This is the same behavior as with file symlinks, but it's worth confirming because the stakes feel higher with folders.

Checking if something is a symlink and where it points

To see whether a file or folder is actually a symlink, open the terminal in that folder and type ls -l. This lists everything with details.

Look at each line. If it's a symlink, you'll see an arrow (->) pointing to the original. For example:

lrwxrwxrwx 1 username username 45 Jan 15 10:30 report.pdf -> /home/username/Documents/ProjectA/report.pdf

The l at the very start (instead of -) also signals a symlink. The path after the arrow is where the symlink points. If the original file has been moved or deleted, you might see the arrow pointing to a path that no longer exists — that's a broken symlink.

You can also use readlink /path/to/symlink to see only the target path, without all the other details.

Removing symlinks safely

To delete a symlink, use rm /path/to/symlink — the same command you'd use to delete any file. This removes only the link itself, not the original file or folder it points to.

This is actually one of the safest things about symlinks: you can delete them without worrying about losing the real data. The original stays exactly where it is.

If you want to remove a symlink to a folder, rm still works. Do not use rm -r (recursive delete) on a symlink to a folder, because on some systems that can delete the contents of the original folder instead of just the link. Stick with plain rm.

What happens when the original file moves or gets deleted

If you move or rename the original file, the symlink breaks. It still exists, but it points to a path that no longer has anything at the end of it. The symlink becomes useless until you either move the original back or delete the broken symlink and create a new one pointing to the new location.

You can identify broken symlinks by running ls -l and looking for arrows that point to paths in red text (in most terminal setups), or by trying to open the symlink and getting a "file not found" error.

If you know you're going to move the original file, delete the symlink first, move the file, then create a new symlink pointing to the new location. This prevents confusion and broken links sitting around.

Frequently Asked Questions

Can I create a symlink to a file that doesn't exist yet?

Technically yes — the command will succeed and create a broken symlink. But this is rarely useful. Create the original file first, then create the symlink. That way you know the link actually points somewhere.

What's the difference between ln -s and ln without the -s?

Without the -s, ln creates a hard link, which is a direct reference to the file's data on disk rather than a path to another file. Hard links are more complex and have limitations (they don't work across different storage drives, and they don't work on folders). Use ln -s for symlinks, which is what most people need.

Can I create a symlink in a folder I don't have write permission for?

No. You need write permission in the folder where the symlink will live. If you get a "permission denied" error, try adding sudo before the command: sudo ln -s /path/to/original /path/to/symlink. You'll be asked for your password.

Do symlinks work if I move the symlink to a different folder?

Yes, as long as you used an absolute path when you created it. The symlink will still point to the original file no matter where you move the link itself. If you used a relative path, moving the symlink will break it.

What happens if I edit a file through a symlink?

You're editing the original file. Changes show up in both the symlink and the original because they're the same file. This is the whole point — symlinks keep everything in sync.