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

ARGUMENTS

159       hardlink takes one or more directories which will be searched for files
160       to be linked.
161

BUGS

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

AUTHOR

176       There are multiple hardlink implementations. The very first
177       implementation is from Jakub Jelinek for Fedora distribution, this
178       implementation has been used in util-linux between versions v2.34 to
179       v2.36. The current implementations is based on Debian version from
180       Julian Andres Klode.
181

REPORTING BUGS

183       For bug reports, use the issue tracker at
184       https://github.com/util-linux/util-linux/issues.
185

AVAILABILITY

187       The hardlink command is part of the util-linux package which can be
188       downloaded from Linux Kernel Archive
189       <https://www.kernel.org/pub/linux/utils/util-linux/>.
190
191
192
193util-linux 2.39.2                 2023-07-12                       HARDLINK(1)
Impressum