Lesson 3.7: Hard and symbolic links
How a name points to a file (inodes), hard links as a second name for the same data, symbolic links as signposts to a path, link counts, broken links and when to use which.
15 min
You will learn to
- Explain inodes and why a file can have two names
- Create symbolic links with ln -s and hard links with ln
- Read link counts, -> targets and inode numbers in ls -li
- Recognise a broken symbolic link
Key terms
- Inode
- The record where the filesystem keeps a file's data location, size, owner, permissions and times. It has a number, but no name.
- Directory entry
- A name inside a directory that points to an inode. The name lives in the directory, not in the file.
- Hard link
- An additional directory entry for the same inode: a second, fully equal name for the same data. Created with ln.
- Symbolic link (symlink, soft link)
- A tiny file that contains a path to another file or directory. Programs follow it automatically. Created with ln -s.
- Link count
- The number of names (hard links) an inode has; shown after the permissions in ls -l. The data is deleted only when it drops to 0.
- Broken (dangling) link
- A symbolic link whose target no longer exists.
← More ways to look at text: head, tail, wc, sort and uniq · All lessons · Compressing and archiving files →