Vol. I · No. 46The command line sectionSat, 10 Oct 2026
Linux · file management

ln

one file, another name

ln makes links. A symbolic link, made with -s, is a small file that points at another path — like a shortcut. A hard link is a second name for the very same data, indistinguishable from the first.

A symbolic link points at a name; a hard link points at the data itself.

Symbolic
ln -s target name
the common kind
Hard
ln target name
same inode, same disk only
Order
Target, then name
the same order as cp
Broken link
Target removed
the link remains, pointing nowhere

At the terminal

Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.

user@netflow — bashcoreutils
$ ln -s /var/www/site current
$ ls -l current
1lrwxrwxrwx 1 user user 13 Sep 30 12:01 current -> /var/www/site
2$ ln notes.txt notes-hard.txt
$ ls -li notes.txt notes-hard.txt
31311234 -rw-r--r-- 2 user user 2048 Sep 30 10:40 notes-hard.txt
1311234 -rw-r--r-- 2 user user 2048 Sep 30 10:40 notes.txt
4$ ln -sfn /var/www/site-v2 current
Illustrative session · names, sizes and dates are examples, and every address is from a documentation or private range
Reading the output

What the numbered lines are telling you

1
A symbolic link

The leading l marks it, and the arrow shows where it points. Its size, 13, is just the length of the path it holds.

2
No -s: a hard link

A second name is added for the same file. Nothing is copied.

3
Same inode, link count 2

Both names show inode 1311234, and the count after the permissions is 2. Deleting one name leaves the data reachable by the other.

4
Repointing a link

-f replaces the existing link and -n stops ln from descending into the directory it points at. This is how a release is switched over.

Switches

A switch changes how the command behaves. These are the ones used day to day; man ln lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.

-s
Symbolic: make a link that points to a path. Without it, a hard link.
-f
Force: replace a link or file that already has the name.
-n
Treat an existing link to a directory as a file, so it is replaced rather than entered.
-r
Relative: work out the relative path to the target for you.
-v
Verbose: print each link made.

Variations worth knowing

The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.

readlink -f current

Prints the final path a link resolves to.

ln -s ../shared/config.yml config.yml

A relative link, which keeps working if the whole tree is moved.

find . -xtype l

Finds broken symbolic links — ones whose target no longer exists.

unlink current

Removes a link without touching what it points to. rm does the same.

In cybersecurity

A link makes a program act on a different file from the one it named.

Symlink attacks

If a privileged program writes to a predictable name in /tmp, a user can put a link there first and redirect the write to a file of their choosing.

Links out of a web root

A symbolic link inside a served directory can expose files outside it. Web servers have settings to refuse to follow them.

Hard links keep data alive

Deleting a file does not free it while another hard link exists. The kernel restricts hard-linking to files you do not own for this reason.

Filed under

File management

Read alongside