Hard Links and Soft Links

Hard Links and Soft Links

The inodes

An?inode?is something that contains the full description of a file or directory, including what it contains and its location on the hard drive. An?inode?does not have a fixed value. Indeed, it contains several data which have variable values which will change according to the use. It can be considered as the ID Card of a file or directory.

What is a Hard Link?

A hard link is a link that directly associates a name with a given file in an operating system, even if the file is renamed, a hard link will still be pointing to that file. This also means that the hard link you make to a file, will affect the file.

How to create a Hard Link

No alt text provided for this image

( ln test hardLink ) lets break this down

  • ln used to create the link to the file
  • test (original file path)
  • hardLink (new file path)

This creates another pointer to the exact same data.

Now I can read the file with: cat hardLink

When changes are made to one filename, the other reflects those changes. The permissions, link count, ownership, timestamps, and file content are the exact same. If the original file is deleted, the data still exists under the secondary hard link. The data is only removed from your drive when all links to the data have been removed.

But a Hard Link cannot be created for a folder or file in a different file system.

Now, what is a Soft (symbolic) Link?

A Soft Link it's a special file that points to an existing file. Same as Hard Links, any changes to the data in either file is reflected in the other. Basically are shortcuts to a file. Unlike a Hard Link, it does not changes the pointer when the file is renamed, if any changes are made to the file, the Soft Link will point to nothing.

How to create a Soft Link

No alt text provided for this image

( ln -s test softLink ) lets also break this down

  • ln used the link to the file
  • -s It's a ln option to create a Symbolic Link
  • test (file path you want to point to)
  • softLink (new file path)

Soft Links can point to another file or directory in any file system.

Hard Link or Soft Link?

It really depends on the situation, use it at your convenience

  • A hard link always points a filename to data on a storage device.
  • A soft link always points a filename to another filename, which then points to information on a storage device.

That's all, thanks for reading! :)

要查看或添加评论,请登录

Ignacio Peralta的更多文章

  • Recursion

    Recursion

    What is Recursion? Recursion is the process of repeating items in a self-similar way. In programming languages, if a…

  • Static Libraries vs. Dynamic Libraries

    Static Libraries vs. Dynamic Libraries

    Why using libraries? In programming, a library is a collection of pre-compiled pieces of code that can be reused in a…

    1 条评论
  • Static Libraries in C

    Static Libraries in C

    What is a C static library? One of the tools that compilers supply us with are libraries. A library is a file…

  • GCC - Steps of compilation

    GCC - Steps of compilation

    What is GCC? This acronym stands for GNU Compiler Collection, is an integrated distribution of compilers for several…

社区洞察

其他会员也浏览了