{
    "mode": "man",
    "parameter": "HARDLINK",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/HARDLINK/1/json",
    "generated": "2026-10-22T13:20:00Z",
    "synopsis": "hardlink [options] [directory|file]...",
    "sections": {
        "NAME": {
            "content": "hardlink - link multiple copies of a file\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "hardlink [options] [directory|file]...\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "hardlink is a tool that replaces copies of a file with either hardlinks or copy-on-write\nclones, thus saving space.\n\nhardlink first creates a binary tree of file sizes and then compares the content of files\nthat have the same size. There are two basic content comparison methods. The memcmp method\ndirectly reads data blocks from files and compares them. The other method is based on\nchecksums (like SHA256); in this case for each data block a checksum is calculated by the\nLinux kernel crypto API, and this checksum is stored in userspace and used for file\ncomparisons.\n\nFor each file also an \"intro\" buffer (32 bytes) is cached. This buffer is used independently\nfrom the comparison method and requested cache-size and io-size. The \"intro\" buffer\ndramatically reduces operations with data content as files are very often different from the\nbeginning.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "-h --help",
                    "content": "Display help text and exit.\n",
                    "flag": "-h",
                    "long": "--help"
                },
                {
                    "name": "-V --version",
                    "content": "Print version and exit.\n",
                    "flag": "-V",
                    "long": "--version"
                },
                {
                    "name": "-c --content",
                    "content": "Consider only file content, not attributes, when determining whether two files are equal.\nSame as -pot.\n",
                    "flag": "-c",
                    "long": "--content"
                },
                {
                    "name": "-b --io-size _",
                    "content": "The size of the read(2) or sendfile(2) buffer used when comparing file contents. The size\nargument may be followed by the multiplicative suffixes KiB, MiB, etc. The \"iB\" is\noptional, e.g., \"K\" has the same meaning as \"KiB\". The default is 8KiB for memcmp method\nand 1MiB for the other methods. The only memcmp method uses process memory for the\nbuffer, other methods use zero-copy way and I/O operation is done in the kernel. The size\nmay be altered on the fly to fit a number of cached content checksums.\n",
                    "flag": "-b",
                    "long": "--io-size"
                },
                {
                    "name": "-d --respect-dir",
                    "content": "Only try to link files with the same directory name. The top-level directory (as\nspecified on the hardlink command line) is ignored. For example, hardlink --respect-dir\n/foo /bar will link /foo/some/file with /bar/some/file, but not /bar/other/file. If\ncombined with --respect-name, then entire paths (except the top-level directory) are\ncompared.\n",
                    "flag": "-d",
                    "long": "--respect-dir"
                },
                {
                    "name": "-f --respect-name",
                    "content": "Only try to link files with the same (base)name. It’s strongly recommended to use long\noptions rather than -f which is interpreted in a different way by other hardlink\nimplementations.\n",
                    "flag": "-f",
                    "long": "--respect-name"
                },
                {
                    "name": "-i --include _",
                    "content": "A regular expression to include files. If the option --exclude has been given, this\noption re-includes files which would otherwise be excluded. If the option is used without\n--exclude, only files matched by the pattern are included.\n",
                    "flag": "-i",
                    "long": "--include"
                },
                {
                    "name": "-m --maximize",
                    "content": "Among equal files, keep the file with the highest link count.\n",
                    "flag": "-m",
                    "long": "--maximize"
                },
                {
                    "name": "-M --minimize",
                    "content": "Among equal files, keep the file with the lowest link count.\n",
                    "flag": "-M",
                    "long": "--minimize"
                },
                {
                    "name": "-n --dry-run",
                    "content": "Do not act, just print what would happen.\n",
                    "flag": "-n",
                    "long": "--dry-run"
                },
                {
                    "name": "-o --ignore-owner",
                    "content": "Link and compare files even if their owner information (user and group) differs. Results\nmay be unpredictable.\n",
                    "flag": "-o",
                    "long": "--ignore-owner"
                },
                {
                    "name": "-O --keep-oldest",
                    "content": "Among equal files, keep the oldest file (least recent modification time). By default, the\nnewest file is kept. If --maximize or --minimize is specified, the link count has a\nhigher precedence than the time of modification.\n",
                    "flag": "-O",
                    "long": "--keep-oldest"
                },
                {
                    "name": "-p --ignore-mode",
                    "content": "Link and compare files even if their mode is different. Results may be slightly\nunpredictable.\n",
                    "flag": "-p",
                    "long": "--ignore-mode"
                },
                {
                    "name": "-q --quiet",
                    "content": "Quiet mode, don’t print anything.\n",
                    "flag": "-q",
                    "long": "--quiet"
                },
                {
                    "name": "-r --cache-size _",
                    "content": "The size of the cache for content checksums. All non-memcmp methods calculate checksum\nfor each file content block (see --io-size), these checksums are cached for the next\ncomparison. The size is important for large files or a large sets of files of the same\nsize. The default is 10MiB.\n",
                    "flag": "-r",
                    "long": "--cache-size"
                },
                {
                    "name": "-s --minimum-size _",
                    "content": "The minimum size to consider. By default this is 1, so empty files will not be linked.\nThe size argument may be followed by the multiplicative suffixes KiB (=1024), MiB\n(=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB and YiB (the \"iB\" is optional, e.g.,\n\"K\" has the same meaning as \"KiB\").\n",
                    "flag": "-s",
                    "long": "--minimum-size"
                },
                {
                    "name": "-S --maximum-size _",
                    "content": "The maximum size to consider. By default this is 0 and 0 has the special meaning of\nunlimited. The size argument may be followed by the multiplicative suffixes KiB (=1024),\nMiB (=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB and YiB (the \"iB\" is optional,\ne.g., \"K\" has the same meaning as \"KiB\").\n",
                    "flag": "-S",
                    "long": "--maximum-size"
                },
                {
                    "name": "-t --ignore-time",
                    "content": "Link and compare files even if their time of modification is different. This is usually a\ngood choice.\n",
                    "flag": "-t",
                    "long": "--ignore-time"
                },
                {
                    "name": "-v --verbose",
                    "content": "Verbose output, explain to the user what is being done. If specified once, every\nhardlinked file is displayed. If specified twice, it also shows every comparison.\n",
                    "flag": "-v",
                    "long": "--verbose"
                },
                {
                    "name": "-x --exclude _",
                    "content": "A regular expression which excludes files from being compared and linked.\n",
                    "flag": "-x",
                    "long": "--exclude"
                },
                {
                    "name": "-X --respect-xattrs",
                    "content": "Only try to link files with the same extended attributes.\n",
                    "flag": "-X",
                    "long": "--respect-xattrs"
                },
                {
                    "name": "-y --method _",
                    "content": "Set the file content comparison method. The currently supported methods are sha256, sha1,\ncrc32c and memcmp. The default is sha256, or memcmp if Linux Crypto API is not available.\nThe methods based on checksums are implemented in zero-copy way, in this case file\ncontents are not copied to the userspace and all calculation is done in kernel.\n\n--reflink[=when]\nCreate copy-on-write clones (aka reflinks) rather than hardlinks. The reflinked files\nshare only on-disk data, but the file mode and owner can be different. It’s recommended\nto use it with --ignore-owner and --ignore-mode options. This option implies\n--skip-reflinks to ignore already cloned files.\n\nThe optional argument when can be never, always, or auto. If the when argument is\nomitted, it defaults to auto, in this case, hardlink checks filesystem type and uses\nreflinks on BTRFS and XFS only, and fallback to hardlinks when creating reflink is\nimpossible. The argument always disables filesystem type detection and fallback to\nhardlinks, in this case, only reflinks are allowed.\n",
                    "flag": "-y",
                    "long": "--method"
                },
                {
                    "name": "--skip-reflinks",
                    "content": "Ignore already cloned files. This option may be used without --reflink when creating\nclassic hardlinks.\n",
                    "long": "--skip-reflinks"
                }
            ]
        },
        "ARGUMENTS": {
            "content": "hardlink takes one or more directories which will be searched for files to be linked.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "The original hardlink implementation uses the option -f to force hardlinks creation between\nfilesystem. This very rarely usable feature is no more supported by the current hardlink.\n\nhardlink assumes that the trees it operates on do not change during operation. If a tree does\nchange, the result is undefined and potentially dangerous. For example, if a regular file is\nreplaced by a device, hardlink may start reading from the device. If a component of a path is\nreplaced by a symbolic link or file permissions change, security may be compromised. Do not\nrun hardlink on a changing tree or on a tree controlled by another user.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "There are multiple hardlink implementations. The very first implementation is from Jakub\nJelinek for Fedora distribution, this implementation has been used in util-linux between\nversions v2.34 to v2.36. The current implementations is based on Debian version from Julian\nAndres Klode.\n",
            "subsections": []
        },
        "REPORTING BUGS": {
            "content": "For bug reports, use the issue tracker at https://github.com/util-linux/util-linux/issues.\n",
            "subsections": []
        },
        "AVAILABILITY": {
            "content": "The hardlink command is part of the util-linux package which can be downloaded from Linux\nKernel Archive <https://www.kernel.org/pub/linux/utils/util-linux/>.\n\nutil-linux 2.39.3                            2023-11-21                                  HARDLINK(1)",
            "subsections": []
        }
    },
    "summary": "hardlink - link multiple copies of a file",
    "flags": [
        {
            "flag": "-h",
            "long": "--help",
            "arg": null,
            "description": "Display help text and exit."
        },
        {
            "flag": "-V",
            "long": "--version",
            "arg": null,
            "description": "Print version and exit."
        },
        {
            "flag": "-c",
            "long": "--content",
            "arg": null,
            "description": "Consider only file content, not attributes, when determining whether two files are equal. Same as -pot."
        },
        {
            "flag": "-b",
            "long": "--io-size",
            "arg": null,
            "description": "The size of the read(2) or sendfile(2) buffer used when comparing file contents. The size argument may be followed by the multiplicative suffixes KiB, MiB, etc. The \"iB\" is optional, e.g., \"K\" has the same meaning as \"KiB\". The default is 8KiB for memcmp method and 1MiB for the other methods. The only memcmp method 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."
        },
        {
            "flag": "-d",
            "long": "--respect-dir",
            "arg": null,
            "description": "Only try to link files with the same directory name. The top-level directory (as specified on the hardlink command line) is ignored. For example, hardlink --respect-dir /foo /bar will link /foo/some/file with /bar/some/file, but not /bar/other/file. If combined with --respect-name, then entire paths (except the top-level directory) are compared."
        },
        {
            "flag": "-f",
            "long": "--respect-name",
            "arg": null,
            "description": "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."
        },
        {
            "flag": "-i",
            "long": "--include",
            "arg": null,
            "description": "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."
        },
        {
            "flag": "-m",
            "long": "--maximize",
            "arg": null,
            "description": "Among equal files, keep the file with the highest link count."
        },
        {
            "flag": "-M",
            "long": "--minimize",
            "arg": null,
            "description": "Among equal files, keep the file with the lowest link count."
        },
        {
            "flag": "-n",
            "long": "--dry-run",
            "arg": null,
            "description": "Do not act, just print what would happen."
        },
        {
            "flag": "-o",
            "long": "--ignore-owner",
            "arg": null,
            "description": "Link and compare files even if their owner information (user and group) differs. Results may be unpredictable."
        },
        {
            "flag": "-O",
            "long": "--keep-oldest",
            "arg": null,
            "description": "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."
        },
        {
            "flag": "-p",
            "long": "--ignore-mode",
            "arg": null,
            "description": "Link and compare files even if their mode is different. Results may be slightly unpredictable."
        },
        {
            "flag": "-q",
            "long": "--quiet",
            "arg": null,
            "description": "Quiet mode, don’t print anything."
        },
        {
            "flag": "-r",
            "long": "--cache-size",
            "arg": null,
            "description": "The size of the cache for content checksums. All non-memcmp methods 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 is 10MiB."
        },
        {
            "flag": "-s",
            "long": "--minimum-size",
            "arg": null,
            "description": "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\")."
        },
        {
            "flag": "-S",
            "long": "--maximum-size",
            "arg": null,
            "description": "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\")."
        },
        {
            "flag": "-t",
            "long": "--ignore-time",
            "arg": null,
            "description": "Link and compare files even if their time of modification is different. This is usually a good choice."
        },
        {
            "flag": "-v",
            "long": "--verbose",
            "arg": null,
            "description": "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."
        },
        {
            "flag": "-x",
            "long": "--exclude",
            "arg": null,
            "description": "A regular expression which excludes files from being compared and linked."
        },
        {
            "flag": "-X",
            "long": "--respect-xattrs",
            "arg": null,
            "description": "Only try to link files with the same extended attributes."
        },
        {
            "flag": "-y",
            "long": "--method",
            "arg": null,
            "description": "Set the file content comparison method. The currently supported methods are sha256, sha1, crc32c and memcmp. The default is sha256, or memcmp if Linux Crypto API is not available. The methods based on checksums are implemented in zero-copy way, in this case file contents are not copied to the userspace and all calculation is done in kernel. --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 it with --ignore-owner and --ignore-mode options. This option implies --skip-reflinks to ignore already cloned files. 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."
        },
        {
            "flag": "",
            "long": "--skip-reflinks",
            "arg": null,
            "description": "Ignore already cloned files. This option may be used without --reflink when creating classic hardlinks."
        }
    ],
    "examples": [],
    "see_also": [],
    "tldr": {
        "source": "official",
        "description": "Consolidate duplicate files by replacing them with hard links.",
        "examples": [
            {
                "description": "Simulate hardlinking duplicate files without modifying them",
                "command": "hardlink {{-n|--dry-run}} {{path/to/directory}}"
            },
            {
                "description": "Hardlink duplicate files in a directory",
                "command": "hardlink {{path/to/directory}}"
            },
            {
                "description": "Hardlink duplicate files in multiple directories",
                "command": "hardlink {{path/to/directory1 path/to/directory2 ...}}"
            },
            {
                "description": "Display verbose output while hardlinking",
                "command": "hardlink {{-v|--verbose}} {{path/to/directory}}"
            },
            {
                "description": "Only consider files with a minimum size",
                "command": "hardlink {{-s|--minimum-size}} {{size}} {{path/to/directory}}"
            }
        ]
    }
}