Soft Link Vs. Hard link

Soft Link Vs. Hard link

Understanding the difference between a hard link and a symbolic link requires knowledge of how computers store and access data. A computer's hard drive is composed of switches that represent 1's and 0's, and files are stored as a series of these switches. In order to access a file, the computer must know the physical location of the data within the switch series.

To facilitate this, computers use a data structure called an inode, which contains metadata and a pointer to the data's physical location. Filenames on a computer are actually pointers to inodes, and directories serve as a way to organize these filenames. Inodes act as intermediaries between the name of the file and its actual location on the hard drive.

This is where hard links and symbolic links come into play. For example, if you create a file called "file1", the computer creates a link from the filename to its corresponding inode, which in turn points to the physical storage location of the file. If you create a hard link called "h-link", it points to the same inode that "file1" does. However, if you create a symbolic link called "s-link", it points to the filename "file1" rather than to the inode.

In summary, hard links and symbolic links are different ways of linking filenames to their corresponding data on a computer's hard drive. Hard links point directly to the inode, while symbolic links point to the filename itself. Understanding the differences between these types of links is crucial for effective file management on a computer system.

Look at the image below.

No hay texto alternativo para esta imagen

In Linux:

  • Touch [filename] = Create a new file

No hay texto alternativo para esta imagen

  • ln [filename] [hardlink] = Creates a hard link

No hay texto alternativo para esta imagen

  • ln -s [filename] [symbolic link] = Creates a symbolic link

No hay texto alternativo para esta imagen

which one to use?

There are advantages and disadvantages to both approaches.

When you move or delete the original file named "file1," the "h-link" points to the previously assigned inode, preserving the relevant data. However, the "f-link" becomes obsolete because it can no longer locate the original file name.

On the other hand, creating an "f-link" on a second file system is straightforward - you can simply create a link to a file name. However, this is not possible with "h-link" since it cannot locate the inode if you are in a different file system.

In summary, both "h-link" and "f-link" have their benefits and limitations, depending on the situation at hand.

Click for more information about.

.

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

Juan Sebastian Gonzalez的更多文章

  • Recursion

    Recursion

    What is it? Essentially is a technique that split a situation or a problem into shorter pieces of itself. Take a look…

  • Mutable, Immutable... everything is an object! O.o

    Mutable, Immutable... everything is an object! O.o

    In Python, everything is an object, which means every entity has some metadata (called attributes) and associated…

  • Differences between static and dynamic libraries

    Differences between static and dynamic libraries

    A library is a powerful tool in a programmer's arsenal, consisting of pre-compiled functions that can be easily reused…

  • How integers are stored in memory using two’s complement

    How integers are stored in memory using two’s complement

    A computer is an amalgamation of hardware and software, where digital memories store information in bits (short for…

  • The worst abuse of the C preprocessor (IOCCC winner, 1986)

    The worst abuse of the C preprocessor (IOCCC winner, 1986)

    obfuscation is the deliberate act of creating machine code that is difficult for humans to understand. This article is…

  • C static libraries

    C static libraries

    This article is about exploring in C what are the static libraries, why should we use them, how they work, how can be…

  • Compilation Process using in programs like C.

    Compilation Process using in programs like C.

    In programming, there are two types of languages, which are interpreted and compilated. The code of compiled language…

社区洞察

其他会员也浏览了