Create and Change Hard and Symbolic Links

Exam Objectives Covered:

  • Create links
  • Identify hard and/or soft links
  • Copying versus linking files
  • Use links to support system administration tasks

Links in Linux are synonymous with shortcuts in the Windows world. They are not identical, but the idea is similar.  Specifically, the command ‘ln’, is used to make links between files. There are two types of links, symbolic and hard. The following definitions come from Practice Labs:

Symbolic links: It is a pointer to the source file. The permissions that apply to the source file also apply to the symbolic link. It can point to a source file on the local or remote filesystem.

Hard links: It is another directory entry for the source file and carries that same properties, such as file permissions, of the source file. If you delete one file, the other file remains intact. A hard link must exist in the same local filesystem.

The interesting thing about links is that a hard link is tied to the original file, but not dependent on it. This means that if you create a hard link to a file and then delete the original, the linked file will still work. This is not the case with a symbolic link. If you create a symbolic link and remove the original file, the symbolic link will not have anything to link to. A way to be sure that your links are bound, or not, to the original file is by listing the directory, using ‘ls’, with the -i option. This prints the index number of each file.

To support system administration, links are useful when you do not want to make multiple copies of the same file. If you were to update a file, you would have to make the same changes on all the files. If you use hard links, then when you update the file, your changes are seen in all links.

Another situation in which links support system administration is when linking shared objects. The link can make it easier to reference frequently used libraries. It also aides in version control. Application developers can link to shared objects using major versions. Administrators can link shared objects to the major versions. This allows multiple versions to exist for compatibility reasons. If you list the contents of the ‘/lib64’ directory, you will see something like this: ->

The developer can reference the ‘’ shared object, but the administrator can install any variant of the libcrypt library. This means that if an update were to come out or an older version was needed, it could be located in /lib64 under the naming conventions and linked to the single named variant.

Hard Links and Symbolic Links

To view examples of creating symbolic and hard links, take a look at the screenshots below. You will see the hard link and the original file have the same inode. The symbolic link has a different inode and therefore is not the same file.

To create a hard link:

Example: ln original-file hard-link

To create a symbolic link:

Syntax: ln [-s|--symbolic] TARGET LINK_NAME
Example: ln -s original-file symbolic-link

Leave a Reply

Your email address will not be published. Required fields are marked *