Config Router

  • Google Sheets
  • CCNA Online training
    • CCNA
  • CISCO Lab Guides
    • CCNA Security Lab Manual With Solutions
    • CCNP Route Lab Manual with Solutions
    • CCNP Switch Lab Manual with Solutions
  • Juniper
  • Linux
  • DevOps Tutorials
  • Python Array
You are here: Home / What is the difference between a symbolic link and a hard link?

What is the difference between a symbolic link and a hard link?

August 20, 2021 by James Palmer

Underneath the file system, files are represented by inodes. (Or is it multiple inodes? Not sure.)
A file in the file system is basically a link to an inode.
A hard link, then, just creates another file with a link to the same underlying inode.
When you delete a file, it removes one link to the underlying inode. The inode is only deleted (or deletable/over-writable) when all links to the inode have been deleted.
A symbolic link is a link to another name in the file system.
Once a hard link has been made the link is to the inode. Deleting, renaming, or moving the original file will not affect the hard link as it links to the underlying inode. Any changes to the data on the inode is reflected in all files that refer to that inode.
Note: Hard links are only valid within the same File System. Symbolic links can span file systems as they are simply the name of another file.

Some examples that might help.
Create two files with data in them:
$ printf Cat > foo
$ printf Dog > bar

Create a hard and soft (aka symbolic) link:
$ ln foo foo-hard
$ ln -s bar bar-soft

List directory contents in long format by increasing size:
ls -lrS
lrwxr-xr-x 1 user staff 3 3 Apr 15:25 bar-soft -> bar
-rw-r–r– 2 user staff 4 3 Apr 15:25 foo-hard
-rw-r–r– 2 user staff 4 3 Apr 15:25 foo
-rw-r–r– 1 user staff 4 3 Apr 15:25 bar

This tell us that

1st column: the file mode for the soft and hard links differ

soft link: lrwxr-xr-x

filetype: l = symbolic link
owner permissions: rwx = readable, writable, executable
group permissions: r-x = readable, not writable, executable
other permissions: r-x = readable, not writable, executable

hard link: -rw-r–r–

filetype: – = regular file
owner permissions: rw- = readable, writable, not executable
group permissions: r– = readable, not writable, not executable
other permissions: r– = readable, not writable, not executable

2nd column: number of links is higher for the hard linked files

5th column: the size of the soft link is smaller, because it’s a reference as opposed to a copy

last column: the symbolic link shows the linked-to file via ->

Changing the filename of foo does not affect foo-hard:
$ mv foo foo-new
$ cat foo-hard
Cat

Changing the contents of foo is reflected in foo-hard:
$ printf Dog >> foo
$ cat foo-hard
CatDog

Hard links like foo-hard point to the inode, the contents, of the file.
This is not the case for soft links like bar-soft:
$ mv bar bar-new
$ ls bar-soft
bar-soft
$ cat bar-soft
cat: bar-soft: No such file or directory

The contents of the file could not be found because the soft link points to the name, that was changed, and not to the contents.
Likewise, If foo is deleted, foo-hard still holds the contents; if bar is deleted, bar-soft is just a link to a non-existing file.

Related

Filed Under: Uncategorized

Recent Posts

  • How do I give user access to Jenkins?
  • What is docker volume command?
  • What is the date format in Unix?
  • What is the difference between ARG and ENV Docker?
  • What is rsync command Linux?
  • How to Add Music to Snapchat 2021 Android? | How to Search, Add, Share Songs on Snapchat Story?
  • How to Enable Snapchat Notifications for Android & iPhone? | Steps to Turn on Snapchat Bitmoji Notification
  • Easy Methods to Fix Snapchat Camera Not Working Black Screen Issue | Reasons & Troubleshooting Tips to Solve Snapchat Camera Problems
  • Detailed Procedure for How to Update Snapchat on iOS 14 for Free
  • What is Snapchat Spotlight Feature? How to Make a Spotlight on Snapchat?
  • Snapchat Hack Tutorial 2021: Can I hack a Snapchat Account without them knowing?

Copyright © 2025 · News Pro Theme on Genesis Framework · WordPress · Log in