04. The Linux Command Line Ultimate Tutorial – HARD vs SYMBOLIC LINKS

Video is ready, Click Here to View ×

This episode shows the difference between hard and soft/symbolic links and how to use them.

To create a hard link you need to use this command:

ln file_name hard_link

To create a symbolic link you need to use this command:

ln -s file_name soft_link.

The Linux Command Line Ultimate Tutorial series aims to help you to master the power of the Linux Command Line.

All Episodes of The Linux Command Line Ultimate Tutorial series…


  1. Hello ALU ! Everything would have been crystal clear if you had used the command ls -li. Then everybody would have seen the inodes and would have understood it better. It is also the reason that some people while having a 1TB hard drive can' t create new files because there are no inodes anymore even if there is still plenty of space on the hard drive !!!
    Best regards,

  2. One thing you have demonstrated without pointing it out, is that symlinks can use relative or absolute paths. For example, that path to the YouTube directory was absolute (began with “/”), while the initial demo links were relative. Relative paths are interpreted relative to the directory containing the symlink: thus, if the link begins with “../”, then that means go to the parent directory of the one containing the link, and so on.

  3. Multiple hard links to the same file all equally “own” the file — none of them is treated specially over the others. Whereas soft links don’t “own” what they point to — you can still remove it and leave the soft link pointing to something that doesn’t exist. You can even freely create soft links that point nowhere. The usefulness of this is when you tell a program to create a file with that pathname, it gets actually created in the location the link points to.

  4. So am I right in thinking about them like this:

    A soft link is like a link on a web browser. You use it to access data that is stored elsewhere, and changing that data makes the link invalid e.g. changing the file name or deleting it.

    A hard link is like a duplicate file, but both duplicates are synced, so every write to one is mirrored exactly on the other – like a synced cloud storage where you can edit the file from the web server or a local copy, and both copies of the file have the same changes effected on them.

  5. You just described in about 10 minutes crucial thing I love unix for. Filesystem design is absolutely godlike. Like, I can have gazillions of physical hard drives constantly being replaced/broken/moved/backuped/etc, with countless remote modules (ftp, sftp, samba, cloud providers) attached via fuse as well, and none of this ongoing mount/unmount/connect/disconnect events will affect my filesystem hierarchy at all, if I just properly manage symlinks (not to mention windows filesystem is just a nightmare that way). Absolutely critical thing for highload servers for example, and also convenient for home usage.
    The second major thing is a pipelines and I/O mechanism in general, amazingly demonstrated by Brian Kernigan himself countless amount of times. Hope you'll do a video about it.

  6. Interesting! So, what is the different between creating a hard link and creating a copy (using the command cp)?

    This is my hypothesis: Say that you create a file call Book.txt and write so much in this file that it becomes 1024 kB large. When you create a hard link to the file (ls Book.txt "Book Hardlink") and, at the same time, you copy the content of this file (cp Book.txt "Book Copy.txt"). The next day, you continue writing in this file and, all of a sudden, it is 3072 kB in size. When you check the size of the folder, which stores all these files (ls -l), you find out that the copy you created yesterday is unchanged (its size is still 1024 kB), but the hard link you created is up to date (it's size is 3072 kB, just as the original file). This is because the hard links all refer to the same inod, the same data. The copy, on the other hand, is not affected by the changes, because it has a different inod. It's a completely different file, not a copy.
    When you create a copy, you copy all the contents of a file you create a file with a new inod. When you create a hard link, you create a file that refers directly to the same inod. When you create a soft/symbolic link, you create a file that redirects you to the original file, but not directly to the inod.

    Is this correct?

Leave a Reply

Your email address will not be published.