Linux commands: ln
A quick guide to the `ln` command, used to create links in the filesystem
The ln command is part of the Linux file system commands.
It’s used to create links. What is a link? It’s like a pointer to another file. A file that points to another file. You might be familiar with Windows shortcuts. They’re similar.
We have 2 types of links: hard links and soft links.
Hard links
Hard links are rarely used. They have a few limitations: you can’t link to directories, and you can’t link to external filesystems (disks).
A hard link is created using
ln <original> <link>For example, say you have a file called recipes.txt. You can create a hard link to it using:
ln recipes.txt newrecipes.txtThe new hard link you created is indistinguishable from a regular file:

Now any time you edit any of those files, the content will be updated for both.
If you delete the original file, the link will still contain the original file content, as that’s not removed until there is one hard link pointing to it.

Soft links
Soft links are different. They are more powerful as you can link to other filesystems and to directories, but when the original is removed, the link will be broken.
You create soft links using the -s option of ln:
ln -s <original> <link>For example, say you have a file called recipes.txt. You can create a soft link to it using:
ln -s recipes.txt newrecipes.txtIn this case you can see there’s a special l flag when you list the file using ls -al, and the file name has a @ at the end, and it’s colored differently if you have colors enabled:

Now if you delete the original file, the links will be broken, and the shell will tell you “No such file or directory” if you try to access it:

This command works on Linux, macOS, WSL, and anywhere you have a UNIX environment
download all my books for free
- javascript handbook
- typescript handbook
- css handbook
- node.js handbook
- astro handbook
- html handbook
- next.js pages router handbook
- alpine.js handbook
- htmx handbook
- react handbook
- sql handbook
- git cheat sheet
- laravel handbook
- express handbook
- swift handbook
- go handbook
- php handbook
- python handbook
- cli handbook
- c handbook
subscribe to my newsletter to get them
Terms: by subscribing to the newsletter you agree the following terms and conditions and privacy policy. The aim of the newsletter is to keep you up to date about new tutorials, new book releases or courses organized by Flavio. If you wish to unsubscribe from the newsletter, you can click the unsubscribe link that's present at the bottom of each email, anytime. I will not communicate/spread/publish or otherwise give away your address. Your email address is the only personal information collected, and it's only collected for the primary purpose of keeping you informed through the newsletter. It's stored in a secure server based in the EU. You can contact Flavio by emailing [email protected]. These terms and conditions are governed by the laws in force in Italy and you unconditionally submit to the jurisdiction of the courts of Italy.