Controlling Files with jdupes Hardlinks: A Guide

Abstract: Resolve unpredictable file retention when using jdupes hardlinks by explicitly specifying keep-newer, keep-older, or keep-first flags.

Created: 2026-10-23 by

jdupes uses the --link flag to replace duplicate files with hardlinks, preserving one copy and pointing all others to the same inode. To control which file is kept as the primary reference, you must use the --keep-newer, --keep-older, or --keep-first options explicitly. Without these flags, jdupes defaults to keeping the first file encountered in its scan order, which can lead to unexpected retention of temporary or system files if not managed carefully.

Understanding Hardlinks and Deduplication

Before executing any deduplication commands, it is crucial to understand what a hardlink actually does. A hardlink is not a shortcut or a symbolic link; it is an additional directory entry that points to the same underlying data blocks on the disk. When you create a hardlink, you are essentially giving the same file two different names within the filesystem structure. The operating system tracks how many hardlinks point to a specific inode. The data remains on the disk only as long as at least one hardlink exists. If you delete all hardlinks for a particular set of duplicates, the data is permanently removed. This behavior is fundamentally different from creating copies. When you use standard copy commands, each file occupies its own separate space on the storage medium. With hardlinks, multiple filenames share the exact same physical location. This means that modifying one "duplicate" will instantly reflect in all other linked files because they are, technically, the same file. This property makes hardlinks incredibly efficient for saving space, especially when dealing with large media libraries or backup directories where identical files exist in multiple locations. For more context on how the operating system tracks these links, you might find Understanding the Hardlinks Field of a Directory helpful.

The Standard Deduplication Command

The core command used to perform deduplication via hardlinks in jdupes is --link. This is the standard and most commonly used mode for reducing disk usage. When you run jdupes with this flag, the tool scans the specified directories, identifies files with identical content, and then replaces the duplicates with hardlinks. It is important to note that there is no such thing as a --harder flag in jdupes. Any guide suggesting otherwise is incorrect. The correct syntax involves specifying the target directories followed by the --link option. For example, a basic command might look like this:
jdupes --link /path/to/source/dir
When you execute this command, jdupes will first perform a dry-run style analysis if you do not specify a write mode, but --link is inherently destructive to the duplicate files. It removes the duplicate entries and creates hardlinks in their place. Always ensure you have backups before running this command, as the operation cannot be easily undone. The tool will prompt you for confirmation before making changes, but relying on prompts alone is risky in automated scripts.

Controlling Which File Is Preserved

One of the most critical aspects of using jdupes is deciding which file remains after deduplication. By default, jdupes keeps the first file it encounters in its internal list of duplicates. This order is determined by how the filesystem returns directory entries, which is often arbitrary and not based on creation time or alphabetical order. This unpredictability can cause issues if you want to preserve newer versions of documents or older versions of archived data. To gain precise control, you should use specific flags that dictate the retention policy. The --keep-newer flag ensures that the most recently modified file is preserved, while all older duplicates are replaced with hardlinks to it. This is ideal for document management where you want to keep the latest edits. Conversely, --keep-older preserves the oldest file, which might be useful for maintaining historical archives without deleting early versions. Another option is --keep-first, which explicitly enforces the default behavior of keeping the first file found, making your intent clear to anyone reading the script. You can combine these flags with other options to refine the process. For instance, you might want to exclude certain types of files from being linked. Using --exclude allows you to specify patterns for files that should never be touched, regardless of their duplication status. This prevents accidental hardlinking of system files or configuration files that might behave unexpectedly if shared across multiple paths.

Verification and Safety Checks

Before committing to a full deduplication, it is wise to run jdupes in report mode. Using the --print flag allows you to see exactly which files would be affected without making any changes. This output lists groups of duplicate files, showing you which ones would be kept and which would be replaced. Reviewing this list helps you verify that your retention policies are working as expected. You can also use --quiet to suppress verbose output during the actual linking phase, keeping your terminal clean. Additionally, consider the implications of hardlinks on file permissions and ownership. Since hardlinks share the same inode, they also share the same permissions and ownership attributes. If you have files with different permission requirements that happen to have identical content, hardlinking them will force them to share the same permissions. This can lead to security issues if a file intended to be private becomes accessible due to its hardlinked counterpart. Always audit your file permissions after running jdupes to ensure no unintended access has been granted.

Common Pitfalls and Best Practices

A common mistake users make is assuming that hardlinks work across different filesystems or partitions. Hardlinks rely on the underlying inode structure, which is local to a single filesystem. If you attempt to hardlink a file from an external USB drive to an internal SSD, jdupes will fail because the inodes are not compatible across different mount points. In such cases, you must use symbolic links or copy the data instead. Understanding these limitations prevents wasted time and potential data loss. Another pitfall involves symlinks. If your directory contains symbolic links that point to duplicate files, jdupes may follow these links and create hardlinks to the target of the symlink. This can result in complex chains of links that are difficult to manage. It is generally recommended to use the --no-symlinks flag if you want to avoid following symbolic links during the scan. This ensures that only regular files are considered for deduplication. Finally, always test your setup on a small subset of files before applying it to your entire library. Create a temporary directory with known duplicates and run your preferred jdupes command. Verify that the correct files are preserved and that the space savings match your expectations. This practice builds confidence in your workflow and helps you catch any configuration errors before they impact your valuable data. For related insights on managing file histories, you may also want to read How to Clear Recent Files History in Linux without Deleting Actual Files? to understand how metadata interacts with file structures.

Frequently Asked Questions

Can I undo a jdupes hardlink operation?

No, you cannot simply "unlink" a hardlink to restore the original duplicate file. Once a file is replaced with a hardlink, the original unique data is gone unless you have a backup. The hardlink points to the same inode as the remaining file, so deleting the hardlink just reduces the link count but does not recover the deleted data. Always maintain backups before running deduplication tools.

Does jdupes work on network drives like NFS?

It depends on the implementation of the network filesystem. Traditional NFS versions may not support hardlinks reliably, or they may treat them differently than local filesystems. Some modern NFS implementations do support hardlinks, but you should test thoroughly. If the network protocol does not guarantee inode consistency, jdupes may produce errors or incorrect results. Local filesystems are the safest environment for hardlink operations.

What happens if I modify a file after it has been hardlinked?

Since all hardlinked files share the same inode, modifying one file modifies all of them. You will not see separate copies; instead, every filename pointing to that inode will show the updated content. This is why it is critical to choose the correct file to keep. If you need independent copies, you must use symbolic links or copy the data before linking.

Can I use jdupes to compress duplicate files?

No, jdupes does not perform compression. It only creates hardlinks to save space by eliminating redundant data blocks. If you want to compress files, you should use tools like gzip or bzip2 separately. Combining hardlinks with compression requires careful handling, as compressing one hardlink affects all linked files. jdupes focuses solely on deduplication through linking.

Why did jdupes skip some duplicate files?

jdupes skips files that do not meet the criteria defined by your flags. Common reasons include excluded file types, files on different filesystems, or files with different permissions if strict matching is enabled. Check the verbose output or logs to see why specific files were ignored. Ensuring that all target files are on the same partition and have compatible permissions usually resolves this issue.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More