user4523703
user4523703

Reputation:

Linux: what is link

I'm new in Linux I'm just using windwos GUI before but I have a question: what is LINK in Linux? I know it have tow type but I don't know what is the advantage of them normally in windows has shortcut to reference app from the difference path if LINK in Linux have the same feature why it have tow type?

Thank you to answer.

Upvotes: 2

Views: 479

Answers (3)

dburcu
dburcu

Reputation: 151

Links are a very handy way to create a shortcut to an original directory. Links are used in many instances: Sometimes to create a convenient path to a directory buried deep within the file hierarchy; other uses for links include:

  1. Linking libraries

  2. Making sure files are in constant locations (without having to move the original)

  3. Keeping a “copy” of a single file in multiple locations.

In Linux there are two different types of links:

  1. Hard links

  2. Symbolic links

    The difference between the two are significant. With hard links, you can only link to files (and not directories); you cannot reference a file on a different disk or volume, and they reference the same inode as the original source. A hard link will continue to remain usable, even if the original file is removed. Symbolic links, on the other hand, can link to directories, reference a file/folder on a different disk or volume, will exist as a broken (unusable) link if the original location is deleted, reference abstract filenames and directories (as opposed to physical locations), and are given their own, unique inode.

Upvotes: 0

Ega
Ega

Reputation: 55

First You should be know what is Inode ? to understand advantage of link type let me

An inode is an entry in inodetable, containing information ( the metadata ) about a regular file and directory. An inode is a data structure on a traditional Linux file system such as ext3 or ext4. Inode number also called as index number , it consists following attributes.

  • File types ( executable, block special etc)
  • Permissions ( read, write etc)
  • UID ( Owner )
  • GID ( Group )
  • FileSize
  • Time stamps including last access, last modification and last inode number change.
  • File deletion time
  • Number of links ( soft/hard )
  • Location of file on harddisk.
  • Some other metadata about file.

to Display Inode use this command+flags

ls –il

What is a link?

A link is simply a way to refer to the contents of a file.

Types of link:

  1. Hardlink(Another name for the file/inode in the disk)
  2. Softlink/symbolic link (Pointer to the file location)

How to create Links in linux ?

  1. Hard link ln existingfile newfile

    Note : Hardlinksare not allowed for directories

  2. Soft link ln –s existingfile newfile

A soft link will have a different Inode number than the source file, which will be having a pointer to the source file but hard link will be using the same Inode number as the source file. Soft link is like shortcut in windows. It doesn’t contain any information about the destination file or contents of the file, instead of that, it simply contains the pointer to the location of the destination file. Soft Links You can make links for files & folder & you can create link (shortcut) on different partition & got different inode number from original. If real copy is deleted the link will not work. Hard Links For files only & you cannot create on different partition ( it should be on same partition ) & got same inode number as original If therealcopy is deleted the link will work( because it act as original file )

Upvotes: 2

Thomas Dickey
Thomas Dickey

Reputation: 54515

There are two types because it evolved that way -- and they are implemented differently:

  • hard links came first. Every file is represented in a directory file by a name and inode value. Think of inode as the disk-address or block number. A hard-linked file's inode is in more than one directory file (or more than once in a given directory file, using a different filename), and each directory entry is the "same" file (different names, of course).
  • symbolic links came later. They are a special entry in a directory file which have the name of another file rather than an inode value.

There is a clear distinction between a symbolic link and the actual file to which it points: if you remove the file, you have a broken link. This is different from hard links - removing one name will not damage the other(s).

Upvotes: 2

Related Questions