hardlink - link multiple copies of a file
hardlink [options] [directory|file]...
hardlink is a tool that replaces copies of a file with either hardlinks or copy-on-write clones, thus saving space.
hardlink first creates a binary tree of file sizes and then compares the content of files that have the same size. There are two basic content comparison methods. The memcmp method directly reads data blocks from files and compares them. The other method is based on checksums (like SHA256); in this case for each data block a checksum is calculated by the Linux kernel crypto API, and this checksum is stored in userspace and used for file comparisons.
For each file also an "intro" buffer (32 bytes) is cached. This buffer is used independently from the comparison method and requested cache-size and io-size. The "intro" buffer dramatically reduces operations with data content as files are very often different from the beginning.
-y, --method name
The optional argument when can be never, always, or auto. If the when argument is omitted, it defaults to auto, in this case, hardlink checks filesystem type and uses reflinks on BTRFS and XFS only, and fallback to hardlinks when creating reflink is impossible. The argument always disables filesystem type detection and fallback to hardlinks, in this case, only reflinks are allowed.
-x, --exclude regex
-i, --include regex
-s, --minimum-size size
-S, --maximum-size size
-b, --io-size size
-r, --cache-size size
hardlink takes one or more directories which will be searched for files to be linked.
The original hardlink implementation uses the option -f to force hardlinks creation between filesystem. This very rarely usable feature is no more supported by the current hardlink.
hardlink assumes that the trees it operates on do not change during operation. If a tree does change, the result is undefined and potentially dangerous. For example, if a regular file is replaced by a device, hardlink may start reading from the device. If a component of a path is replaced by a symbolic link or file permissions change, security may be compromised. Do not run hardlink on a changing tree or on a tree controlled by another user.
There are multiple hardlink implementations. The very first implementation is from Jakub Jelinek for Fedora distribution, this implementation has been used in util-linux between versions v2.34 to v2.36. The current implementations is based on Debian version from Julian Andres Klode.
For bug reports, use the issue tracker at <https://github.com/util-linux/util-linux/issues>.
The hardlink command is part of the util-linux package which can be downloaded from Linux Kernel Archive <https://www.kernel.org/pub/linux/utils/util-linux/>.