1HARDLINK(1)                      User Commands                     HARDLINK(1)
2
3
4

NAME

6       hardlink - link multiple copies of a file
7

SYNOPSIS

9       hardlink [options] [directory|file]...
10

DESCRIPTION

12       hardlink is a tool that replaces copies of a file with either hardlinks
13       or copy-on-write clones, thus saving space.
14
15       hardlink first creates a binary tree of file sizes and then compares
16       the content of files that have the same size. There are two basic
17       content comparison methods. The memcmp method directly reads data
18       blocks from files and compares them. The other method is based on
19       checksums (like SHA256); in this case for each data block a checksum is
20       calculated by the Linux kernel crypto API, and this checksum is stored
21       in userspace and used for file comparisons.
22
23       For each file also an "intro" buffer (32 bytes) is cached. This buffer
24       is used independently from the comparison method and requested
25       cache-size and io-size. The "intro" buffer dramatically reduces
26       operations with data content as files are very often different from the
27       beginning.
28

OPTIONS

30       -h, --help
31           Display help text and exit.
32
33       -V, --version
34           Print version and exit.
35
36       -v, --verbose
37           Verbose output, explain to the user what is being done. If
38           specified once, every hardlinked file is displayed. If specified
39           twice, it also shows every comparison.
40
41       -q, --quiet
42           Quiet mode, don’t print anything.
43
44       -n, --dry-run
45           Do not act, just print what would happen.
46
47       -y, --method name
48           Set the file content comparison method. The currently supported
49           methods are sha256, sha1, crc32c and memcmp. The default is sha256,
50           or memcmp if Linux Crypto API is not available. The methods based
51           on checksums are implemented in zero-copy way, in this case file
52           contents are not copied to the userspace and all calculation is
53           done in kernel.
54
55       --reflink[=when]
56           Create copy-on-write clones (aka reflinks) rather than hardlinks.
57           The reflinked files share only on-disk data, but the file mode and
58           owner can be different. It’s recommended to use it with
59           --ignore-owner and --ignore-mode options. This option implies
60           --skip-reflinks to ignore already cloned files.
61
62           The optional argument when can be never, always, or auto. If the
63           when argument is omitted, it defaults to auto, in this case,
64           hardlink checks filesystem type and uses reflinks on BTRFS and XFS
65           only, and fallback to hardlinks when creating reflink is
66           impossible. The argument always disables filesystem type detection
67           and fallback to hardlinks, in this case, only reflinks are allowed.
68
69       --skip-reflinks
70           Ignore already cloned files. This option may be used without
71           --reflink when creating classic hardlinks.
72
73       -f, --respect-name
74           Only try to link files with the same (base)name. It’s strongly
75           recommended to use long options rather than -f which is interpreted
76           in a different way by other hardlink implementations.
77
78       -p, --ignore-mode
79           Link and compare files even if their mode is different. Results may
80           be slightly unpredictable.
81
82       -o, --ignore-owner
83           Link and compare files even if their owner information (user and
84           group) differs. Results may be unpredictable.
85
86       -t, --ignore-time
87           Link and compare files even if their time of modification is
88           different. This is usually a good choice.
89
90       -c --content
91           Consider only file content, not attributes, when determining
92           whether two files are equal. Same as -pot.
93
94       -X, --respect-xattrs
95           Only try to link files with the same extended attributes.
96
97       -m, --maximize
98           Among equal files, keep the file with the highest link count.
99
100       -M, --minimize
101           Among equal files, keep the file with the lowest link count.
102
103       -O, --keep-oldest
104           Among equal files, keep the oldest file (least recent modification
105           time). By default, the newest file is kept. If --maximize or
106           --minimize is specified, the link count has a higher precedence
107           than the time of modification.
108
109       -x, --exclude regex
110           A regular expression which excludes files from being compared and
111           linked.
112
113       -i, --include regex
114           A regular expression to include files. If the option --exclude has
115           been given, this option re-includes files which would otherwise be
116           excluded. If the option is used without --exclude, only files
117           matched by the pattern are included.
118
119       -s, --minimum-size size
120           The minimum size to consider. By default this is 1, so empty files
121           will not be linked. The size argument may be followed by the
122           multiplicative suffixes KiB (=1024), MiB (=1024*1024), and so on
123           for GiB, TiB, PiB, EiB, ZiB and YiB (the "iB" is optional, e.g.,
124           "K" has the same meaning as "KiB").
125
126       -S, --maximum-size size
127           The maximum size to consider. By default this is 0 and 0 has the
128           special meaning of unlimited. The size argument may be followed by
129           the multiplicative suffixes KiB (=1024), MiB (=1024*1024), and so
130           on for GiB, TiB, PiB, EiB, ZiB and YiB (the "iB" is optional, e.g.,
131           "K" has the same meaning as "KiB").
132
133       -b, --io-size size
134           The size of the read(2) or sendfile(2) buffer used when comparing
135           file contents. The size argument may be followed by the
136           multiplicative suffixes KiB, MiB, etc. The "iB" is optional, e.g.,
137           "K" has the same meaning as "KiB". The default is 8KiB for memcmp
138           method and 1MiB for the other methods. The only memcmp method uses
139           process memory for the buffer, other methods use zero-copy way and
140           I/O operation is done in the kernel. The size may be altered on the
141           fly to fit a number of cached content checksums.
142
143       -r, --cache-size size
144           The size of the cache for content checksums. All non-memcmp methods
145           calculate checksum for each file content block (see --io-size),
146           these checksums are cached for the next comparison. The size is
147           important for large files or a large sets of files of the same
148           size. The default is 10MiB.
149

ARGUMENTS

151       hardlink takes one or more directories which will be searched for files
152       to be linked.
153

BUGS

155       The original hardlink implementation uses the option -f to force
156       hardlinks creation between filesystem. This very rarely usable feature
157       is no more supported by the current hardlink.
158
159       hardlink assumes that the trees it operates on do not change during
160       operation. If a tree does change, the result is undefined and
161       potentially dangerous. For example, if a regular file is replaced by a
162       device, hardlink may start reading from the device. If a component of a
163       path is replaced by a symbolic link or file permissions change,
164       security may be compromised. Do not run hardlink on a changing tree or
165       on a tree controlled by another user.
166

AUTHOR

168       There are multiple hardlink implementations. The very first
169       implementation is from Jakub Jelinek for Fedora distribution, this
170       implementation has been used in util-linux between versions v2.34 to
171       v2.36. The current implementations is based on Debian version from
172       Julian Andres Klode.
173

REPORTING BUGS

175       For bug reports, use the issue tracker at
176       https://github.com/util-linux/util-linux/issues.
177

AVAILABILITY

179       The hardlink command is part of the util-linux package which can be
180       downloaded from Linux Kernel Archive
181       <https://www.kernel.org/pub/linux/utils/util-linux/>.
182
183
184
185util-linux 2.38.1                 2022-08-04                       HARDLINK(1)
Impressum