Linux and Networking

Linux and Networking

3.16 Links

3.16.1 Hard links

  • A “hard” link (hard link) is a new reference to the same file; consists of a new directory entry pointing to an existing file pointed to from another directory entry.
  • The content is on one side only, but the file can be accessed from several places, possibly with different names.
hard link
hard link

 

Example: 

echo ‘Hi all!’ > bye

ln bye bye.ln0

 

ln creates a second name referring to the same file; no copy is made, create a link (link). Verify that :

echo ‘Hello again everyone!’ > bye

ln bye bye.ln0

 

ls -l bye*

 

shows a count of 2 in the links column. When creating the link with the ln command, notice that the existing file goes first, then one or more link names to create.

 

When a file with multiple links is deleted, only the link is deleted.

 

The file is actually deleted only when the last link disappears.

 

ln dir2 dir2ln

 

Important: you cannot create a hard link for a directory.

 

3.16.2 Symbolic links.

 

  • A symbolic link (symbolic link) is a file that points to another file or directory.
  • The symbolic link file contains only the path of the other file or directory.

 

ln -s note note.ls0

create note.ls0 as symbolic link.

 

ln -s dir2 dir2ls

creates dir2ls as a symbolic link to a directory.

ls -l

displays the letter l in the file type to indicate that it is a symbolic link.

ls dir2

ls dir2ls

show the same file content.

ls -l dir2ls

shows that it is a symbolic link and indicates where it points to.

The Demeter Project