You asked: What is link in Linux?

A link in UNIX is a pointer to a file. Like pointers in any programming languages, links in UNIX are pointers pointing to a file or a directory. Creating links is a kind of shortcuts to access a file. Links allow more than one file name to refer to the same file, elsewhere.

A link is a symbolic connection or pointer to a single file that allows you to access it from more than one directory. A symbolic link is created when you link files between directories. … When you link files in the same directory, a symbolic link is created.

To make links between files you need to use ln command. A symbolic link (also known as a soft link or symlink) consists of a special type of file that serves as a reference to another file or directory. Unix/Linux like operating systems often uses symbolic links.

To view the symbolic links in a directory:

  1. Open a terminal and move to that directory.
  2. Type the command: ls -la. This shall long list all the files in the directory even if they are hidden.
  3. The files that start with l are your symbolic link files.

To remove a symbolic link, use either the rm or unlink command followed by the name of the symlink as an argument. When removing a symbolic link that points to a directory do not append a trailing slash to the symlink name.

The concept of a hard link is the most basic we will discuss today. Every file on the Linux filesystem starts with a single hard link. The link is between the filename and the actual data stored on the filesystem. … This means that the two filenames, though different, point to identical data.

Hard link is the exact replica of the actual file it is pointing to . Both the hard link and the linked file shares the same inode . If the source file is deleted ,the hard link still works and you will be able to access the file until the number of hard links to file isn’t 0(zero).

In the case of a regular file, the link count is the number of hard links to that file. However, Unix file systems don’t let you create hard links to directories, yet the link count on a directory is always at least two, and even increases by one for each sub-directory in that directory.

The reason hard-linking directories is not allowed is a little technical. Essentially, they break the file-system structure. You should generally not use hard links anyway. Symbolic links allow most of the same functionality without causing problems (e.g ln -s target link ).

Like this post? Please share to your friends:
OS Today