]>
Commit | Line | Data |
---|---|---|
295b3979 | 1 | //po4a: entry man manual |
6c64d12d MB |
2 | //// |
3 | SPDX-License-Identifier: MIT | |
4 | ||
5 | Copyright (C) 2008 - 2012 Julian Andres Klode. See hardlink.c for license. | |
6 | Copyright (C) 2021 Karel Zak <kzak@redhat.com> | |
7 | //// | |
8 | = hardlink(1) | |
9 | :doctype: manpage | |
10 | :man manual: User Commands | |
11 | :man source: util-linux {release-version} | |
12 | :page-layout: base | |
13 | :command: hardlink | |
14 | ||
15 | == NAME | |
16 | ||
17 | hardlink - link multiple copies of a file | |
18 | ||
19 | == SYNOPSIS | |
20 | ||
21 | *hardlink* [options] [_directory_|_file_]... | |
22 | ||
23 | == DESCRIPTION | |
24 | ||
66a38e97 | 25 | *hardlink* is a tool which replaces copies of a file with hardlinks or copy-on-write clones, therefore saving space. |
6c64d12d | 26 | |
344b0cd4 | 27 | *hardlink* creates a binary tree from file sizes and after that, it compares files with the same sizes. There are two basic content comparison methods. *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 is calculated checksum by Linux kernel crypto API, and this checksum is stored in userspace and used for files comparison. For each file is also cached "intro" buffer (32 bytes), this buffer is used independently on 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. |
f3212b91 | 28 | |
6c64d12d MB |
29 | == OPTIONS |
30 | ||
2b2d3172 MB |
31 | include::man-common/help-version.adoc[] |
32 | If specified once, every hardlinked file is displayed, if specified twice, it also shows every comparison. | |
6c64d12d MB |
33 | |
34 | *-q*, *--quiet*:: | |
2c646c80 | 35 | Quiet mode, don't print anything. |
6c64d12d MB |
36 | |
37 | *-n*, *--dry-run*:: | |
2c646c80 | 38 | Do not act, just print what would happen. |
6c64d12d | 39 | |
259bed15 KZ |
40 | *-y*, *--method* _name_:: |
41 | Set the file content comparison method. The currently supported methods are | |
344b0cd4 | 42 | sha256, sha1, crc32c and memcmp. The default is sha256, or memcmp if Linux |
259bed15 | 43 | Crypto API is not available. The methods based on checksums are implemented in |
344b0cd4 | 44 | zero-copy way, in this case file contents are not copied to the userspace and all |
259bed15 KZ |
45 | calculation is done in kernel. |
46 | ||
66a38e97 KZ |
47 | *--reflink*[=_when_]:: |
48 | Create copy-on-write clones (aka reflinks) rather than hardlinks. The reflinked files | |
49 | share only on-disk data, but the file mode and owner can be different. It's recommended | |
50 | to use it with *--ignore-owner* and *--ignore-mode* options. This option implies | |
51 | *--skip-reflinks* to ignore already cloned files. | |
52 | + | |
53 | The optional argument _when_ can be *never*, *always*, or *auto*. If the _when_ argument | |
344b0cd4 | 54 | is omitted, it defaults to *auto*, in this case, *hardlink* checks filesystem type and |
66a38e97 | 55 | uses reflinks on BTRFS and XFS only, and fallback to hardlinks when creating reflink is impossible. |
344b0cd4 | 56 | The argument *always* disables filesystem type detection and fallback to hardlinks, in this case, |
66a38e97 KZ |
57 | only reflinks are allowed. |
58 | ||
59 | *--skip-reflinks*:: | |
60 | Ignore already cloned files. This option may be used without *--reflink* when creating classic hardlinks. | |
61 | ||
6c64d12d | 62 | *-f*, *--respect-name*:: |
145d42e9 | 63 | Only try to link files with the same (base)name. It's strongly recommended to use long options rather than *-f* which is interpreted in a different way by other *hardlink* implementations. |
6c64d12d MB |
64 | |
65 | *-p*, *--ignore-mode*:: | |
145d42e9 | 66 | Link and compare files even if their mode is different. Results may be slightly unpredictable. |
6c64d12d MB |
67 | |
68 | *-o*, *--ignore-owner*:: | |
145d42e9 | 69 | Link and compare files even if their owner information (user and group) differs. Results may be unpredictable. |
6c64d12d MB |
70 | |
71 | *-t*, *--ignore-time*:: | |
145d42e9 | 72 | Link and compare files even if their time of modification is different. This is usually a good choice. |
6c64d12d MB |
73 | |
74 | *-X*, *--respect-xattrs*:: | |
2c646c80 | 75 | Only try to link files with the same extended attributes. |
6c64d12d MB |
76 | |
77 | *-m*, *--maximize*:: | |
2c646c80 | 78 | Among equal files, keep the file with the highest link count. |
6c64d12d MB |
79 | |
80 | *-M*, *--minimize*:: | |
2c646c80 | 81 | Among equal files, keep the file with the lowest link count. |
6c64d12d MB |
82 | |
83 | *-O*, *--keep-oldest*:: | |
2c646c80 | 84 | Among equal files, keep the oldest file (least recent modification time). By default, the newest file is kept. If *--maximize* or *--minimize* is specified, the link count has a higher precedence than the time of modification. |
6c64d12d MB |
85 | |
86 | *-x*, *--exclude* _regex_:: | |
2c646c80 | 87 | A regular expression which excludes files from being compared and linked. |
6c64d12d MB |
88 | |
89 | *-i*, *--include* _regex_:: | |
2c646c80 | 90 | A regular expression to include files. If the option *--exclude* has 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. |
6c64d12d MB |
91 | |
92 | *-s*, *--minimum-size* _size_:: | |
2c646c80 | 93 | The minimum size to consider. By default this is 1, so empty files will not be linked. The _size_ argument may be followed by the multiplicative suffixes KiB (=1024), MiB (=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB and YiB (the "iB" is optional, e.g., "K" has the same meaning as "KiB"). |
6c64d12d | 94 | |
40a82456 DP |
95 | *-S*, *--maximum-size* _size_:: |
96 | The maximum size to consider. By default this is 0 and 0 has the special meaning of unlimited. The _size_ argument may be followed by the multiplicative suffixes KiB (=1024), MiB (=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB and YiB (the "iB" is optional, e.g., "K" has the same meaning as "KiB"). | |
97 | ||
64c8db3c | 98 | *-b*, *--io-size* _size_:: |
344b0cd4 | 99 | The size of the *read*(2) or *sendfile*(2) buffer used when comparing file contents. |
f3212b91 KZ |
100 | The _size_ argument may be followed by the multiplicative suffixes KiB, MiB, |
101 | etc. The "iB" is optional, e.g., "K" has the same meaning as "KiB". The | |
102 | default is 8KiB for memcmp method and 1MiB for the other methods. The only | |
103 | memcmp method uses process memory for the buffer, other methods use zero-copy | |
104 | way and I/O operation is done in the kernel. The size may be altered on the fly | |
105 | to fit a number of cached content checksums. | |
106 | ||
107 | *-r*, *--cache-size* _size_:: | |
108 | The size of the cache for content checksums. All non-memcmp methods calculate checksum for each | |
344b0cd4 | 109 | file content block (see *--io-size*), these checksums are cached for the next comparison. The |
f3212b91 KZ |
110 | size is important for large files or a large sets of files of the same size. The default is |
111 | 10MiB. | |
259bed15 | 112 | |
6c64d12d MB |
113 | == ARGUMENTS |
114 | ||
115 | *hardlink* takes one or more directories which will be searched for files to be linked. | |
116 | ||
117 | == BUGS | |
118 | ||
119 | 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. | |
120 | ||
e6743239 | 121 | *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. |
6c64d12d MB |
122 | |
123 | == AUTHOR | |
124 | ||
125 | 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. | |
126 | ||
625e9c61 | 127 | include::man-common/bugreports.adoc[] |
6c64d12d | 128 | |
625e9c61 | 129 | include::man-common/footer.adoc[] |
6c64d12d MB |
130 | |
131 | ifdef::translation[] | |
625e9c61 | 132 | include::man-common/translation.adoc[] |
6c64d12d | 133 | endif::[] |