Linux command
hardlink 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Example
hardlink --dry-run /path/to/directory
Example
hardlink /path/to/dir1 /path/to/dir2
Example
hardlink --verbose /path/to/directory
Example
hardlink --minimum-size 1M /path/to/directory
说明
hardlink finds identical files in the given directories and replaces all but one copy with hard links to the remaining file. This saves disk space when the same content exists in multiple places (common with backups, package caches, build artifacts, etc.). The tool compares file contents (not just names or sizes) before linking. It is safe by default: it will not cross filesystem boundaries and will refuse to link files that are not identical. Hard links are directory entries pointing to the same inode. Deleting one name does not affect the others; the data is only removed when the last link is deleted. This makes hardlink particularly useful for deduplicating large static datasets.
参数
- -n, --dry-run
- Do not actually link files, just print what would be done
- -v, --verbose
- Print more information about what is being done
- -s, --minimum-size _size_
- Only hardlink files larger than _size_ (suffixes K, M, G supported)
- -x, --exclude _pattern_
- Skip files matching the given glob pattern (repeatable)
- -i, --include _pattern_
- Only consider files matching the given glob pattern
- -f, --force
- Link files even across different filesystems (dangerous)
FAQ
What is the hardlink command used for?
hardlink finds identical files in the given directories and replaces all but one copy with hard links to the remaining file. This saves disk space when the same content exists in multiple places (common with backups, package caches, build artifacts, etc.). The tool compares file contents (not just names or sizes) before linking. It is safe by default: it will not cross filesystem boundaries and will refuse to link files that are not identical. Hard links are directory entries pointing to the same inode. Deleting one name does not affect the others; the data is only removed when the last link is deleted. This makes hardlink particularly useful for deduplicating large static datasets.
How do I run a basic hardlink example?
Run `hardlink --dry-run /path/to/directory` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -n, --dry-run do in hardlink?
Do not actually link files, just print what would be done