What is a Hard Link in Linux

What is a Hard Link in Linux : How It Differs from a Soft Link

Ready to start learning? Individual Plans →Team Plans →

If you have ever run ln and gotten an invalid cross-device link error, you already know the problem: the command looks right, but the filesystem rules are working against you. A hard link in Linux is not a copy. It is another filename for the same file data, and that distinction changes how deletion, renaming, storage, and troubleshooting work.

Featured Product

CompTIA A+ Certification 220-1201 & 220-1202 Training

Master essential IT skills and prepare for entry-level roles with our comprehensive training designed for aspiring IT support specialists and technology professionals.

Get this course on Udemy at the lowest price →

Quick Answer

A hard link in Linux is an additional directory entry that points to the same inode as an existing file. Both names reference the same data on the same filesystem, so edits appear everywhere, deletion only removes one name, and link creation fails across filesystem boundaries with “invalid cross-device link.”

Definition

A hard link is another directory entry that references the same inode as an existing file in the same filesystem. In Linux, that means two or more filenames can point to one shared file object, with one set of data blocks and one link count.

Commandln source_file link_name
Reference TypeInode-based link, not path-based
Filesystem RuleMust stay on the same filesystem
What Changes?Edits affect all hard links to the same inode
Deletion BehaviorFile data remains until the last link is removed
Common Verificationls -li or stat
Best Use CaseStable multiple names for one local file
Related ConceptSoft link, or symbolic link, points to a pathname

A hard link is a second name for the same file content, not a duplicate of the file. Linux does not care which filename you use to open it; the kernel resolves both names to the same inode and the same data blocks on disk.

That is why changing one hard link changes every other hard link that points to that inode. If report.txt and monthly-report.txt are hard links to the same file, editing one changes the shared file object immediately. There is no hidden copy waiting behind the scenes.

This is also why hard links are storage-efficient. A new hard link adds a directory entry, not a second copy of the file contents. For large files, that difference matters. It also explains why a hard link behaves very differently from a soft link, which points to a pathname instead of file identity.

Linux uses this design because filenames are labels, while inodes are identities. The name can change. The file can be linked from multiple places. The data stays the same until the last link is gone. That model is easy to miss if you think in terms of Windows-style shortcuts or simple copied files.

Red Hat’s inode overview is a useful reference for understanding why the filename is only the front-end and the inode is the real object the filesystem tracks.

In Linux, a filename is a label, but the inode is the identity. A hard link gives you another label for the same identity.

Why Linux Uses Inodes Instead of Filenames

An inode is the filesystem structure that stores metadata for a file and points to the file’s data blocks. It typically includes permissions, ownership, timestamps, file size, and the pointers needed to reach the actual content. The filename itself is stored in the directory, not inside the inode.

This split between pathname and inode is one of the biggest reasons hard links work at all. The directory acts like a lookup table: it maps a visible name to an inode number. When you run cat notes.txt, Linux resolves the path, finds the inode, and opens the file through that identity.

Think of it like a library catalog card and the physical book. The catalog card says where the book is and how to find it, but the card is not the book itself. In Linux, the directory entry is the card, and the inode is the book record that represents the real file.

This design gives you flexibility. A file can be renamed without changing the underlying data. It can be linked from another directory. It can even lose one path entirely and still remain alive through another hard link. For IT administrators, that means file lifecycle and file naming are related, but they are not the same thing.

Linux kernel filesystem documentation explains the underlying model used by Unix-like systems, including how metadata and directory entries interact.

Pro Tip

If you are debugging file behavior, check the inode before you check the filename. The name can mislead you. The inode tells you whether two paths really refer to the same file.

A hard link works by adding another directory entry that points to the same inode. Linux does not duplicate the file’s data blocks. It simply adds another name that resolves to the same file object in the same filesystem.

  1. You create a new directory entry. The ln command adds a second filename in a directory.
  2. The new entry points to the same inode. Linux records that both names reference the same file identity.
  3. The link count increases. The inode keeps track of how many names point to it.
  4. Reads and writes affect the same content. Any modification through one name is visible through every other hard link.
  5. Deletion removes only one name at a time. The file data remains until the last hard link is gone.

The link count is what surprises most people. If a file has two hard links, deleting one path does not delete the underlying content. It only removes one directory entry. That is why files sometimes appear to “survive” deletion in Linux: the data is still referenced somewhere else.

This matters in scripting and administration. A cleanup job that removes one filename may not free disk space if another hard link still points to the same inode. That is not a bug. It is the expected behavior of Unix-style filesystem semantics.

For a practical debugging mindset, pair this concept with the Debugging process: verify what the system is tracking instead of assuming the visible path tells the whole story.

Understanding hard links becomes much easier once you break the filesystem into a few pieces. Each piece has a specific role, and none of them can be skipped if you want to predict how Linux will behave.

  • Inode — the file identity and metadata record.
  • Directory entry — the human-readable filename that points to the inode.
  • Link count — the number of directory entries referencing the same inode.
  • Data blocks — the actual content stored on disk.
  • Filesystem boundary — the limit that prevents hard links from crossing to another mounted filesystem.
  • Pathname — the full route Linux uses to resolve a file.

These pieces work together. The directory entry gives you the name. The inode tells the system what the file really is. The link count shows whether there are other names still protecting the file from deletion. The data blocks are what you actually edit.

One practical detail deserves extra attention: the link count is not the same as file size, and it is not a measure of how many copies exist. It is a count of how many names point to the same inode. That is why ls -l and ls -li matter so much during troubleshooting.

The official ln manual page is a solid reference for the command behavior, including how hard links are created and where they are allowed.

A soft link, also called a symbolic link, points to a pathname rather than directly to an inode. That one difference drives almost every practical difference between the two link types. A hard link references the file itself. A soft link references the location string used to get to the file.

Hard Link Points to the same inode; continues working as long as the inode still exists on the same filesystem.
Soft Link Points to a pathname; can break if the target is renamed, moved, or deleted.

The practical result is simple. A hard link behaves like another name for the same file. A soft link behaves like a shortcut. If you rename the original file, the hard link still works because the inode did not change. The soft link may fail because its stored path no longer resolves.

This is where the difference between hard link and soft link becomes operational, not theoretical. Hard links are stable, but limited. Soft links are flexible, but fragile. One is not universally better than the other. The right choice depends on whether you care more about file identity or path convenience.

For a quick mental shortcut, remember this: soft link hard link is not a contest between two copies. It is a contest between two different kinds of references.

GNU Coreutils documentation explains the ln behavior and shows the distinction between default hard links and the -s option for symbolic links.

Use a hard link when you want two or more stable names for the same local file content. That is the cleanest use case. You get shared data, no duplication, and behavior that survives simple renames or deletions of one path.

Hard links are especially useful in workflows where a file needs to be accessible from more than one directory without creating a second copy. A common example is local file organization on a single filesystem, where you want one file to appear in two places for convenience or process compatibility.

  • Stable local references — one file can be addressed from more than one directory.
  • Space efficiency — no duplicate data blocks are created.
  • Rename resilience — the file stays available through any remaining hard link.
  • Workflow compatibility — a script or process can keep using a familiar name.

Hard links are a good fit when the file will stay within one filesystem and the goal is identity, not portability. If you expect a file to move across partitions, network shares, or mounted volumes, hard links are the wrong tool.

That restriction is why many administrators rely on soft links for convenience and hard links for controlled, local file management. The use case matters more than the syntax.

For readers building practical Linux skills, the CompTIA A+ Certification 220-1201 & 220-1202 Training course is a good fit when you need to connect filesystem concepts to day-to-day support tasks, especially file organization, troubleshooting, and command-line basics.

A hard link cannot cross filesystem boundaries because inode numbers only have meaning inside one filesystem. When you see the invalid cross-device link error, the syntax is usually fine. The problem is that the source and destination live on different mounted filesystems, and Linux cannot create one inode reference across that boundary.

This is where a lot of people get stuck. A mounted drive, a separate partition, or an external volume may look like just another directory path, but the kernel treats it as a different filesystem. Since hard links depend on inode identity within a single filesystem, the link cannot be created across that divide.

That is also why this behavior differs from copying a file or creating a symbolic link. A copy duplicates content into a new location. A soft link stores a path string and can point across filesystems. A hard link must stay where the inode lives.

If you are comparing behaviors, the question a source and a hard link must be part of the same filesystem. true or false? is straightforward: true. That is not a workaround limitation. It is fundamental to how Linux filesystems work.

The Linux link(2) manual page documents the system call that creates hard links and the filesystem rules behind the operation.

Warning

If you get Invalid cross-device link, do not keep retrying the same command. Check the mount points first. The issue is almost always a filesystem boundary, not a typo.

Hard links to directories are restricted because they can create cycles and break the tree structure the filesystem depends on. Linux filesystems are built around a directory tree, and uncontrolled directory hard links can make that tree loop back on itself or become ambiguous.

That restriction protects filesystem integrity. If directories were freely hard-linked, tools that rely on a clean parent-child structure could get confused, and recursive traversal could become dangerous. In practical terms, the operating system limits normal users from creating a mess that the filesystem cannot safely interpret.

This is one reason hard links are used mainly for regular files. They are powerful there and predictable there. Directory handling is a different problem entirely, and Linux chooses safety over flexibility in that case.

Symbolic links do not have the same limitation because they point to paths, not inodes. That is useful, but it also means soft links can behave very differently from hard links when directories move or disappear.

If you are ever asked given a regular file report.txt, which of the following can increase the link count (as seen in ls -l)? the answer is creating another hard link to that file. The link count goes up when another directory entry points to the same inode.

Creating a hard link is simple: use ln with the source file first and the new link name second. The source is the existing file. The destination is the new filename that will point to the same inode.

  1. Confirm that both paths are on the same filesystem.
  2. Choose the existing file as the source.
  3. Choose a new name in the target directory.
  4. Run ln source_file link_name.
  5. Verify the inode and link count with ls -li.

Example:

ln report.txt archive-report.txt

After this command, report.txt and archive-report.txt point to the same inode. If you edit either file, both names show the updated content. If you remove one name, the other still works.

Common mistakes are easy to spot. People assume ln makes a duplicate file. It does not. People also try to create the link across mounted filesystems and then blame the command. The command is fine. The filesystem rules are not.

The question what is link rate does not apply here in the networking sense. In Linux file linking, what matters is the link count, which tells you how many directory entries reference the inode.

The ls manual page documents the output fields that help you confirm hard-link behavior during verification.

ls -li is the fastest way to verify a hard link because it shows inode numbers and link counts in one place. If two filenames have the same inode number, they are hard links to the same file.

Example output might show two names with the same inode value and a link count of 2. That means both names point to one inode. If you create a third hard link, the link count should increase to 3. If you delete one name, the count should drop back down.

stat is another dependable tool. It gives you deeper metadata, including inode number, permissions, timestamps, and the number of hard links. Use it when you want a more detailed view than ls provides.

  1. Run ls -li filename on both paths.
  2. Compare the inode numbers.
  3. Check the link count column.
  4. Use stat filename for more detail if needed.

When the inode numbers match, the filenames are just alternate names for the same file. When the inode numbers differ, you are looking at separate files, even if the content happens to be identical right now.

The stat manual page is the best reference for interpreting file metadata accurately.

What Are the Most Common Errors and Misconceptions?

The most common mistake is assuming a hard link is a copy. It is not. A copy creates a separate inode and separate data blocks. A hard link creates another name for the same inode. That is why changes show up through both paths.

Another frequent misunderstanding is the invalid cross-device link error. This is not a broken command. It is Linux telling you that the source and destination are on different filesystems. The error is a boundary issue, not a syntax issue.

People also assume that deleting one name deletes the file everywhere. That is false. Deleting one hard link removes one directory entry only. The file data remains until the link count reaches zero.

  • Copy confusion — identical content does not mean identical inodes.
  • Deletion confusion — removing one name does not remove the file if other links remain.
  • Move confusion — renaming a file does not break hard links.
  • Path confusion — soft links depend on the path; hard links depend on the inode.

The quickest way to avoid these mistakes is to inspect the inode number and the link count before you make assumptions. That one habit solves a lot of Linux file workflow problems.

One simple example is renaming a file. If report.txt has a hard link named monthly-report.txt, renaming one filename does not break the other. Both names still point to the same inode, so the file remains accessible under the remaining name.

Another useful example is deletion behavior. If a file is removed from one directory but another hard link still exists somewhere else, the data remains available. That is why disk space may not be freed immediately after a delete operation. The filesystem is waiting for the last reference to disappear.

Editing is also easy to demonstrate. If you open one hard-linked name in a text editor and change the contents, the update appears through every other hard link. That is not synchronization. It is the same file object being modified through a different name.

Now compare that to a soft link. If the original file is deleted, a soft link often becomes broken because its stored pathname no longer points to a valid target. A hard link keeps working as long as the inode still exists.

That difference matters in day-to-day administration. If you need a durable local reference to one file, hard links are useful. If you need a flexible shortcut that can point across filesystem boundaries, a soft link is usually the better tool.

For people trying to connect filesystem rules to real support tasks, that is also why Linux file management is one of the practical skills reinforced in the CompTIA A+ path.

Use hard links carefully and deliberately. The biggest rule is simple: keep them within the same filesystem. If you ignore that, you will hit cross-device errors and waste time troubleshooting the wrong layer.

Verify inode numbers before you assume two files are separate copies. If the inode is the same, you are not looking at two independent files. You are looking at one file with multiple names.

  • Stay on one filesystem — hard links do not cross mounted boundaries.
  • Check inode numbers — use ls -li or stat before making changes.
  • Plan for lifecycle — deleting one link does not remove the file if other links remain.
  • Use soft links when flexibility matters — path-based references are better for moving targets.
  • Avoid hard links for directory workflows — directory hard links are restricted for good reason.

There is also a process question worth asking: do you want shared identity or shared access? If you want shared identity, use a hard link. If you want a convenient pointer that can survive across locations and be easier to replace, use a soft link.

If you are comparing them during troubleshooting, remember this practical rule: hard links are durable but rigid. Soft links are flexible but fragile. That tradeoff explains most file-link behavior in Linux.

Key Takeaway

A hard link is another directory entry pointing to the same inode, not a copy of the file.

A hard link and a soft link solve different problems: inode identity versus path flexibility.

Hard links must stay on the same filesystem, which is why cross-device link errors happen.

Deleting one hard link does not delete the file if other links still exist.

Use ls -li or stat to confirm inode numbers and link counts before you troubleshoot.

How Does This Compare to the AZ-104 Question People Also Search For?

The search phrase how hard is az-104 is unrelated to Linux hard links, but it shows the same pattern of user intent: people want a clear answer before they invest time. For hard links, the concept is not difficult once you stop thinking in terms of copies and start thinking in terms of inodes and directory entries.

That is the key learning curve. The mechanics are simple. The mental model is the hard part. Once you understand that Linux separates name from identity, most hard-link behavior becomes predictable.

Microsoft Learn is the official documentation hub for Microsoft technologies, and it reflects the same practical lesson seen across platforms: precise terminology matters when you are troubleshooting systems. In Linux, the precise terms are inode, directory entry, link count, and filesystem boundary.

For IT support work, this kind of clarity saves time. You stop guessing. You verify the inode, check the mount point, and confirm whether the issue is a hard link, a soft link, or a plain copy.

Featured Product

CompTIA A+ Certification 220-1201 & 220-1202 Training

Master essential IT skills and prepare for entry-level roles with our comprehensive training designed for aspiring IT support specialists and technology professionals.

Get this course on Udemy at the lowest price →

Conclusion

A hard link in Linux is another directory entry that points to the same inode, which means it is a second name for the same file data. It is not a copy. It is not a shortcut. It is shared file identity inside one filesystem.

The most important differences from a soft link are straightforward: a hard link points to an inode, a soft link points to a path. A hard link survives renames and deletions of one name as long as another link remains. A soft link is more flexible, but it can break if the target moves or disappears.

When hard links fail, start with the filesystem boundary, then check inode numbers and link counts. That is the debugging mindset that keeps you from chasing the wrong problem. If the command fails with an invalid cross-device link, the issue is usually location, not syntax.

If you want to build this skill into everyday Linux support work, keep practicing with real files, real mount points, and ls -li. The more you work with hard links directly, the faster the inode model becomes second nature.

CompTIA® and A+™ are trademarks of CompTIA, Inc.

[ FAQ ]

Frequently Asked Questions.

What exactly is a hard link in Linux?

A hard link in Linux is essentially an additional directory entry for an existing file that points directly to the same inode on the filesystem. Unlike a shortcut or symbolic link, a hard link references the actual data on disk, not just the file path. This means multiple filenames can correspond to the same physical file content.

Because hard links share the same inode number, changes made to the file through any hard link are reflected in all other hard links. Deleting one hard link does not remove the underlying data until all hard links to that inode are deleted. This property makes hard links useful for creating multiple names for the same data without duplicating storage.

How does a hard link differ from a soft (symbolic) link?

A hard link points directly to the inode of a file, making it indistinguishable from the original file entry. In contrast, a soft link (or symbolic link) is a separate file that contains a path reference to another file or directory. Essentially, soft links act like shortcuts that point to a target filename.

Because hard links share the same inode, they cannot link to directories or span across different filesystems. Soft links, however, can point to directories and files on different filesystems. Additionally, if the original file is deleted, a hard link still retains the data, while a soft link becomes broken or dangling.

Why do I get an “invalid cross-device link” error when creating hard links?

The “invalid cross-device link” error occurs when you try to create a hard link between files located on different mounted filesystems or partitions. This error happens because hard links must reference the same inode, and inodes are unique only within a single filesystem.

Since hard links cannot span across different devices, attempting to link files across partitions or network mounts will fail. To create a link across filesystems, you should use a symbolic link instead, which can reference paths regardless of the underlying device.

Can I create a hard link to a directory in Linux?

By default, creating hard links to directories is generally prohibited in Linux and most Unix-like systems. This restriction exists because hard links to directories can create cycles in the filesystem hierarchy, complicating traversal and filesystem consistency.

Only the system administrator has limited ability to create such links using specific commands, but it is strongly discouraged and rarely necessary. Symbolic links are the preferred method for referencing directories, as they avoid these issues and offer greater flexibility.

What happens to a file’s data when I delete a hard link?

When you delete a hard link (i.e., remove one filename that points to an inode), the underlying file data remains on the disk as long as there is at least one other hard link referencing the same inode. The filesystem keeps track of the link count associated with each inode to manage this.

Only when the last hard link to a file is deleted does the filesystem free the inode and release the storage space. This behavior ensures that data is preserved until no references remain, providing a reliable way to manage files through multiple names without accidental data loss.

Related Articles

Ready to start learning? Individual Plans →Team Plans →
Discover More, Learn More
Linux File Permissions - Setting Permission Using chmod Discover how to set Linux file permissions effectively using chmod to enhance… Linux File Permissions : What Every Developer Needs to Know Learn essential Linux file permission strategies to prevent deployment failures, enhance security,… chown vs chmod : Understanding the Differences in Linux File Permissions Learn the key differences between chown and chmod in Linux to troubleshoot… btrfs vs zfs : A Side-by-Side Linux File System Review Discover the key differences between btrfs and zfs to optimize your Linux… Linux Config File : Essential Commands You Need to Know Discover essential Linux configuration commands that help you safely manage and troubleshoot… Mastering SCP and SSH Linux Commands Discover how mastering SSH and SCP can streamline your server management, prevent…
FREE COURSE OFFERS