Abstract
- It is like hyperlink on the webpage, that links up the components of File System
Hard File System Link
# Create a hard link to a file:
ln /path/to/file path/to/hardlink
- Pointing to Inode with data
- Must be on the same File System
Space saving
We can have multiple references to a single set of data without duplicating the data. Like an additional name for an existing piece of data on disk. Deleting one hard link does not delete the data, as long as other links to that data remain
Important
When we create a hard link on soft link (
ln existing_symlink hardlink_name
), It just resolves the soft link to its target inode (the real file’s inode) and then creates a new hard link to that inode. So the new hard link points directly to the real file’s inode, not “to the soft link inode”. Deleting the symlink only removes that symlink inode.
Soft (Symbolic) File System Link
- Separate inode containing the path to target file. Become Dangling File System Link if target is deleted
- The size is all about the length of the pathname it stores in the inode
- Across different File System
# To create a symlink:
ln -s <source-location> <symlink-location>
# To symlink, while overwriting existing destination files
ln -sf <source-location> <symlink-location>
Can be used to manage dotfiles
Tools like GNU Stow helps to manage dotfiles in one place in an organised manner, and we can version control it with Git. Refer to Stow has forever changed the way I manage my dotfiles for more details
Dangling File System Link
- A soft link whose stored pathname cannot be resolved to a valid inode (because the target file or directory has been moved or deleted)
Useful Commands
realpath path/to/file_or_directory
- Symbolic link:
realpath
resolves the stored pathname until it reaches the inode, then prints the canonical path (normalised absolute path with no.
or..
left) - Hard link:
realpath
simply normalises the pathname (since the directory entry already points to the inode) - For executables/binaries, reveals the actual file location on disk after resolving symlinks (useful to see where a command is really stored)