How to Create a Hard Link to a File in Linux Using the ln Command

When you create a standard shortcut to a file in Windows (or a symbolic link in Linux), you are creating a tiny pointer file. If you accidentally delete the original source file, the shortcut instantly breaks, leaving you with a useless link pointing to nothing.

In Linux, the ext4 file system allows for a much more powerful concept called a “Hard Link.” A hard link does not point to the name of a file; it points directly to the raw, underlying data blocks (the inode) physically written on the hard drive.

If you create a hard link to a massive video file, you effectively have two identical files in two different folders that share the exact same physical storage space. Most importantly, if you delete the original file, the hard link remains perfectly intact, completely preserving your data.

How to Create a Hard Link

You create hard links using the ln (link) command without any additional flags.

  1. Open your Linux terminal.
  2. The syntax is simple: ln [Target File] [New Link Name].
  3. For example, if you have a critical configuration file in your Documents folder and want to create an identical, linked backup in your home directory, you would type:
    ln /home/user/Documents/config.txt /home/user/config_backup.txt
  4. Press Enter.

Unlike copying (cp), which duplicates the data and wastes disk space, this command executes instantly because it only writes a new directory entry pointing to the exact same physical inode.

Verifying the Link

To prove that both files share the exact same physical data, you can use the ls command with the -i (inode) flag.

ls -li /home/user/Documents/config.txt /home/user/config_backup.txt

The terminal will print the metadata for both files. Look at the very first column of numbers on the far left. Both files will share the exact same numerical string (e.g., 1458923). This proves they are fundamentally the same piece of data. If you open either file and edit the text, the changes will instantly reflect in the other file, because they are the same file.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.