What a symlink is and why you'd use one

A symlink (short for symbolic link) is a file that points to another file or folder somewhere else on your system. When you open a symlink, Linux takes you to the file it points to instead. Think of it like a shortcut on your desktop — the shortcut itself is tiny, but clicking it opens the real program stored elsewhere.

Symlinks are useful when you want the same file accessible from multiple locations without copying it. If you have a large video file in one folder but want to reference it from another project folder, a symlink lets both locations point to the single original file. If you update the original, both locations see the change instantly. You also use symlinks to make long file paths shorter or to organize files logically without moving them.

Linux treats a symlink almost like the real file — you can open it, read it, and edit it — but it takes up almost no disk space because it's just a pointer, not a copy.

Key Takeaways

  • The ln -s command creates a symlink, with the target file first and the link name second: ln -s /path/to/original /path/to/link.
  • A symlink can point to a file or a folder, and you can create it in any directory where you have write permission.
  • Use ls -l to see symlinks — they show an arrow pointing to their target, like mylink -> /home/user/documents/file.txt.
  • A broken symlink (one pointing to a file that no longer exists) still shows up in listings but fails when you try to open it.
  • Delete a symlink with rm just like any file — deleting the symlink does not delete the original file it pointed to.

The basic command to create a symlink

Open a terminal and use the ln command with the -s flag (the s stands for "symbolic"). The format is always: ln -s [target] [link name]. The target is the file or folder you want to point to. The link name is what you want to call the symlink.

Here's a real example. Say you have a document at /home/alice/Documents/project-notes.txt and you want a symlink to it in your Desktop folder:

ln -s /home/alice/Documents/project-notes.txt /home/alice/Desktop/notes-link

After you run this, a file called notes-link appears on your Desktop. When you open it, you're actually reading project-notes.txt from the Documents folder. If you edit it through the symlink, the original file changes.

Creating symlinks to folders

Symlinks work the same way for folders as they do for files — use ln -s with the folder path as the target. For example, if you have a folder at /mnt/external-drive/backups and you want quick access to it from your home directory:

ln -s /mnt/external-drive/backups /home/alice/backups-link

Now backups-link in your home folder acts like a folder. You can navigate into it, add files, delete files — everything you do goes to the real folder on the external drive. The symlink itself takes almost no space.

One important detail: when you create a symlink to a folder, do not add a trailing slash to the target path. Use /mnt/external-drive/backups, not /mnt/external-drive/backups/. The trailing slash can cause unexpected behavior in some commands.

Using absolute vs. relative paths

In the examples above, the target path starts with / — these are absolute paths, which work the same no matter where you run the command from. An absolute path always points to the same location.

You can also use relative paths, which are relative to where the symlink sits. If you're already in the Desktop folder and the target file is in the Documents folder one level up, you could write:

ln -s ../Documents/project-notes.txt notes-link

Relative paths are shorter to type, but they only work if the symlink and target stay in the same folder structure. If you move the symlink to a different location, a relative path breaks. Absolute paths are safer for symlinks you plan to keep long-term, because they keep working even if you reorganize your folders.

Checking if a symlink exists and where it points

List files with ls -l (the l flag shows details) and symlinks appear with an arrow showing what they point to:

ls -l /home/alice/Desktop/notes-link

Output might look like: lrwxrwxrwx 1 alice alice 47 Jan 15 10:22 notes-link -> /home/alice/Documents/project-notes.txt

The l at the start means it's a link. The arrow shows the target. If you want to see only the target without all the other details, use readlink:

readlink /home/alice/Desktop/notes-link

This prints just /home/alice/Documents/project-notes.txt. If the symlink is broken (the target no longer exists), readlink still shows where it's trying to point, even though the file isn't there anymore.

Deleting a symlink safely

Delete a symlink with rm, the same command you use to delete regular files:

rm /home/alice/Desktop/notes-link

This removes only the symlink itself. The original file at /home/alice/Documents/project-notes.txt stays untouched. This is one of the safest things about symlinks — you cannot accidentally delete the real file by deleting the link.

Be careful with one edge case: if you use rm on a symlink to a folder and add a trailing slash, like rm -r /home/alice/backups-link/, you might delete the contents of the real folder instead of just the symlink. To be safe, always delete folder symlinks without the trailing slash: rm /home/alice/backups-link.

Troubleshooting broken symlinks

A symlink breaks when the file or folder it points to gets moved or deleted. The symlink still exists, but opening it fails. You can find broken symlinks with:

find /home/alice -type l -xtype l

This searches from your home folder for all symlinks (-type l) that are broken (-xtype l means the target does not exist). Once you find them, you can delete them or fix them by creating a new symlink to the correct location.

If you moved the target file and want to update the symlink, the easiest approach is to delete the old symlink and create a new one pointing to the new location. There's no built-in command to update a symlink in place.

Frequently Asked Questions

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

Yes. Linux lets you create a symlink pointing to a file that doesn't exist. The symlink itself is created successfully, but it becomes broken until the target file is created. This is sometimes useful for setting up folder structures before files arrive, but usually you'll want the target to exist first.

What's the difference between a symlink and a hard link?

A symlink is a pointer to a file path, like a shortcut. A hard link is a second name for the exact same file on disk — both names point to the same data. Hard links only work for files, not folders, and they're less commonly used. For most purposes, symlinks are what you want. Create a hard link with ln (without the -s flag), but stick with symlinks unless you have a specific reason not to.

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

No. You need write permission on the folder where the symlink will sit. You can create a symlink pointing to a file you can't read (though it will be broken when you try to open it), but you can't create the symlink itself in a read-only folder. Ask your system administrator for write access, or create the symlink in a folder you own.

Do symlinks work across different drives or partitions?

Yes, symlinks work across drives and partitions because they store the full path to the target, not a physical disk location. A symlink on your main drive can point to a file on an external USB drive or a network mount. The only catch is that if you unplug the external drive, the symlink breaks until you plug it back in.

What happens if I copy a symlink?

By default, cp copies the symlink itself, not the file it points to. The new symlink points to the same target as the original. If you want to copy the actual file instead, use cp -L (the L flag tells cp to follow the symlink and copy the real file).