This is another topic in Linux that usually got me thinking in circles. To Create and change hard and symbolic links in Linux is something I don’t usually do on a daily basis as a Sysadmin. Maybe you don’t either. I decided to brew a great cup of Caturra variety coffee at home before taking on this one.

Create links in Linux

Hard links

  • Point directly to the same inode (data on disk).
  • Both files are equal; deleting one does not remove the other unless all links are deleted.
  • Cannot cross filesystems or link directories.
# Create a file
echo "Take this" > /etc/takeapp.conf
# Create a hard link
ln /etc/takeapp.conf /etc/takeapp_hardlink.conf
# Verify (same inode)
ls -li /etc/takeapp*
# inode_number takeapp.conf
# inode_number takeapp_hardlink.conf

Both files now share the same inode. Changing either modifies the same data.

Symbolic (soft) links

  • Work like Windows shortcuts.
  • Store a path that points to the target.
  • Can cross filesystems.
  • Can point to directories.
# Create a symlink
ln -s /etc/myapp.conf /etc/myapp_symlink.conf
# Verify
ls -l /etc/myapp*
# myapp_symlink.conf -> /etc/myapp.conf

Identify hard vs. soft links

  • Hard link: same inode number.
  • Soft link: shows -> in ls -l.
ls -li

For example you will see the below output:

12345 -rw-r--r--  2 root root 20 Jan 1  myapp.conf
12345 -rw-r--r--  2 root root 20 Jan 1  myapp_hardlink.conf
12346 lrwxrwxrwx  1 root root 12 Jan 1  myapp_symlink.conf -> myapp.conf

Copying vs. linking

Copying makes a new file with its own inode:

cp /etc/myapp.conf /etc/myapp_copy.conf

Editing myapp_copy.conf does NOT affect the original.

Use links when you want changes reflected across all references.
Use copy when you want independence.

Use links for sysadmin tasks

Example 1: Easier paths you can create a symlink(soft link)

# Symlink long paths for convenience
ln -s /var/log/nginx/access.log ~/nginx_access.log
tail -f ~/nginx_access.log

Useful for switching config versions. For example:

# Keep multiple configs
/etc/myapp.conf.v1
/etc/myapp.conf.v2
# Use symlink to choose active one
ln -sf /etc/myapp.conf.v2 /etc/myapp.conf
systemctl restart myapp

Also, for shared binaries you can do this:

# Point to a single tool version
ln -s /opt/python3.11/bin/python3 /usr/bin/python3

Key difference recap:

  • Hard links = same inode (data), no arrows.
  • Symlinks = pointer to path, shows ->.
  • Copies = independent files.

Copy vs. Hard Link vs. Soft Link comparison table

FeatureCopyHard LinkSoft (Symbolic) Link
DefinitionIndependent duplicate of fileAnother filename pointing to the same inode (data on disk)A shortcut that stores the path to the target file
InodeNew inodeSame inode as originalDifferent inode, points to original path
File contentsIndependentShared (changes affect all links)Shared (but breaks if target is deleted/moved)
Cross-filesystem?Yes❌ No (must be same filesystem)✅ Yes
Works on directories?✅ Yes❌ No (only files)✅ Yes
If original is deletedCopy remains intactOther links still access data until all are deletedLink becomes broken (dangling symlink)
PerformanceUses more disk spaceEfficient (no duplicate data)Small overhead (stores path only)
Use casesBackup, independenceDuplicate filename for same file (e.g., multiple valid paths)Shortcuts, convenience, version switching

Creating hard and symbolic links in Linux can be tricky to understand. Hopefully this tutorial helps somebody out there. Below are some of my T-Shirt and coffee mugs designs. If you like them you can place an order today. Thanks!

Leave a comment

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