Skip to main content

Hard & Symbolic Links

The ln command is used to create links between files. There are two types of links: HardLinks & Symbolic Links

ln [options] {target name} [link name]
Options Function
-backup Back up existing destination files.
-f Remove existing destination files.
-s Symbolic links.
-i Prompt to remove destination files.
-v Print the name of a file before linking.

Visual representation of a hard link:

[file1] ─┐
         │
[inode X]──> "hello"
         │
[file2] ─┘
Recognising Hard Links

When a file has a hard link on it, the OS doesn't make it massively obvious. IE when you set a symbolic link, it will be obvious when viewing the file that there's an existing link:

lrwxrwxrwx  1 root root       9 Jun 16 14:21 test3.txt -> test1.txt

Example
ln -s /etc/config.cfg ~/myconfig

This creates a symbolic link myconfig in your home directory that points to /etc/config.cfg.