Symbolic Link (Symlink or Soft Link)

A symbolic link is more like a shortcut or alias — it’s a special file that points to the path of another file or directory.

  1. Create a directory mkdir /data.

cd /data (enter)

  1. edit the file - vi xyz.txt to insert the text and save it

Go back to the root (/).

Create a symbolic link called abc pointing to /data/xyz.txt ln -s /data/xyz.txt abc

this creates a symbolic link named abc in your current directory, pointing to /data/xyz.txt

Hard Link

A hard link is when a file has two (or more) names, and all of them are equal. Each name points to the same data on the disk. There is no “main” file or “copy”—they are all the same file from the filesystem’s point of view.

  1. mkdir /test
  2. cd /test
  3. vi file1

(Write something in the file and save it)

  1. ln file1 file2

Now both file1 and file2 are hard links to the same file content. Editing file1 also changes file2, and vice versa. Deleting one does not remove the actual data unless all links are deleted.

ln is the command used to create hard links. Syntax: ln