HARDLINK(1)
๐ HARDLINK(1) โ bestie edition ๐
User Commands โจ
okay so. sit down, grab a snack, because i need to tell you about hardlink, and it's genuinely one of my fave little util-linux girlies. no cap.
๐ธ NAME ๐ธ
hardlink โ link multiple copies of a file ๐ซถ
๐ SYNOPSIS ๐
hardlink [options] directory|file...
โจ DESCRIPTION โจ
hardlink is a tool that replaces copies of a file with either hardlinks or copy-on-write clones, thus saving space. like. she literally gives you your disk space back. iconic behaviour, honestly. ๐
the way it works is: hardlink first creates a binary tree of file sizes, and then compares the content of files that have the same size. so it's not out here comparing everything to everything, she's being efficient about it. main character energy. ๐
there are two basic content comparison methods:
- the
memcmpmethod 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. and bestie, the "intro" buffer dramatically reduces operations with data content as files are very often different from the beginning. so it peeks at the first 32 bytes, goes "nope, not you", and moves on. efficiency queen. ๐
๐ OPTIONS ๐
-c,--contentโ consider only file content, not attributes, when determining whether two files are equal. same as-pot. ๐ซถ-b,--io-sizesize โ the size of theread(2)orsendfile(2)buffer used when comparing file contents. the size argument may be followed by the multiplicative suffixesKiB,MiB, etc. the"iB"is optional, e.g.,"K"has the same meaning as"KiB". the default is8KiBformemcmpmethod and1MiBfor the other methods. the onlymemcmpmethod uses process memory for the buffer, other methods use zero-copy way and I/O operation is done in the kernel. the size may be altered on the fly to fit a number of cached content checksums.-d,--respect-dirโ only try to link files with the same directory name. the top-level directory (as specified on thehardlinkcommand line) is ignored. for example,hardlink --respect-dir /foo /barwill link/foo/some/filewith/bar/some/file, but not/bar/other/file. if combined with--respect-name, then entire paths (except the top-level directory) are compared.-f,--respect-nameโ only try to link files with the same (base)name. it's strongly recommended to use long options rather than-fwhich is interpreted in a different way by otherhardlinkimplementations. ๐จ (see the BUGS section bestie, they did-fdirty)-F,--prioritize-treesโ keep files found in the earliest specified top-level directory if there are multiple identical files in different trees. for example,hardlink foo/ bar/will link files inbar/to equal files in thefoo/directory.-i,--includeregex โ a regular expression to include files. if the option--excludehas been given, this option re-includes files which would otherwise be excluded. if the option is used without--exclude, only files matched by the pattern are included.-l,--list-duplicatesโ don't link anything, but list the absolute path of every duplicate file, one per line, preceded by a unique 16-byte discriminator and a tab. just look, no touch. ๐-m,--maximizeโ among equal files, keep the file with the highest link count.-M,--minimizeโ among equal files, keep the file with the lowest link count.--mountโ do not traverse directories on different filesystems (remain within the same filesystem). stay in your lane, literally. ๐ฆ-n,--dry-runโ do not act, just print what would happen. window shopping, essentially. ๐-o,--ignore-ownerโ link and compare files even if their owner information (user and group) differs. results may be unpredictable. โ ๏ธ-O,--keep-oldestโ among equal files, keep the oldest file (least recent modification time). by default, the newest file is kept. if--maximizeor--minimizeis specified, the link count has a higher precedence than the time of modification.-p,--ignore-modeโ link and compare files even if their mode is different. results may be slightly unpredictable. โ ๏ธ-q,--quietโ quiet mode, don't print anything. ๐คซ-r,--cache-sizesize โ the size of the cache for content checksums. all non-memcmpmethods calculate checksum for each file content block (see--io-size), these checksums are cached for the next comparison. the size is important for large files or a large sets of files of the same size. the default is10MiB.--reflink[=when]โ create copy-on-write clones (aka reflinks) rather than hardlinks. the reflinked files share only on-disk data, but the file mode and owner can be different. it's recommended to use this option together with the--ignore-ownerand--ignore-modeoptions. this option implies--skip-reflinksto ignore already cloned files.
the optional argument when can be never, always, or auto. if the when argument is omitted, it defaults to auto, which means that hardlink checks the filesystem type and uses reflinks on BTRFS, XFS and ZFS only, and falls back to hardlinks when creating a reflink is impossible. the argument always disables filesystem-type detection and the fallback to hardlinks, which means that only reflinks are allowed.
--skip-reflinksโ ignore already cloned files. this option may be used without--reflinkwhen creating classic hardlinks.-s,--minimum-sizesize โ the minimum size to consider. by default this is1, so empty files will not be linked. the size argument may be followed by the multiplicative suffixesKiB(=1024),MiB(=1024*1024), and so on forGiB,TiB,PiB,EiB,ZiBandYiB(the"iB"is optional, e.g.,"K"has the same meaning as"KiB").-S,--maximum-sizesize โ the maximum size to consider. by default this is0and0has the special meaning of unlimited. the size argument may be followed by the multiplicative suffixesKiB(=1024),MiB(=1024*1024), and so on forGiB,TiB,PiB,EiB,ZiBandYiB(the"iB"is optional, e.g.,"K"has the same meaning as"KiB").-t,--ignore-timeโ link and compare files even if their time of modification is different. this is usually a good choice. โจ-v,--verboseโ verbose output, explain to the user what is being done. if specified once, every hardlinked file is displayed. if specified twice, it also shows every comparison. she's telling you EVERYTHING. ๐-x,--excluderegex โ a regular expression that excludes files from being compared and linked. this option can be used multiple times.--exclude-subtreeregex โ a regular expression that excludes entire directories from being compared and linked. this option can also be used multiple times.-X,--respect-xattrsโ only try to link files with the same extended attributes.-y,--methodname โ set the file content comparison method. the currently supported methods aresha256,sha1,crc32c, andmemcmp. the default issha256, ormemcmpif the Linux Crypto API is not available. the methods based on checksums are implemented in a zero-copy way, which means that file contents are not copied to userspace and all calculation is done in the kernel. ๐ฅ-z,--zeroโ separate lines with aNULbyte instead of a newline (for-l).-h,--helpโ display help text and exit.-V,--versionโ display version and exit.
๐ ARGUMENTS ๐
hardlink takes one or more directories which will be searched for files to be linked. yes bestie, plural, she can handle multiple dirs at once. multitasking queen. ๐
๐ง ENVIRONMENT ๐ง
ULFILEEQ_DEBUG=allโ enables debug output for file comparisons.
๐ BUGS ๐
the originalhardlinkimplementation uses the option-fto force hardlinks creation between filesystem. this very rarely usable feature is no more supported by the currenthardlink.
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. ๐จ
like fr fr, bestie, this is the "don't do it" part. the vibe check says NO. ๐ญ
๐ซถ AUTHOR ๐ซถ
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.
๐ REPORTING BUGS ๐
for bug reports, use the issue tracker <https://github.com/util-linux/util-linux/issues>. tell them everything, they wanna know. ๐
โญ AVAILABILITY โญ
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/>. go get her. ๐ฆ
okay that's the whole page!! this was util-linux version 2.42.4, dated 2026-09-21 โ and that's the manual name <pink>HARDLINK(1)</pink> from the User Commands section, in case you were wondering. go save some disk space bestie, ily, bye!! ๐
โจ๐๐
๐ฆ where this page comes from
- arch rolling: util-linux 2.42.4-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause-UC AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND ISC AND LGPL-2.1-or-later AND LicenseRef-PublicDomain
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms