/usr/share/doc/rmlint-doc/html/cautions.html is in rmlint-doc 2.6.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cautions (or why it’s hard to write a dupefinder) — rmlint (2.6.1 Penetrating Pineapple) documentation</title>
<link rel="stylesheet" href="_static/basic.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/bootswatch/readable/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="_static/bootstrap-sphinx.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="file:///usr/share/javascript/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="_static/js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="_static/js/jquery-fix.js"></script>
<script type="text/javascript" src="_static/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="_static/bootstrap-sphinx.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Frequently Asked Questions" href="faq.html" />
<link rel="prev" title="Graphical user interface" href="gui.html" />
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1'>
<meta name="apple-mobile-web-app-capable" content="yes">
</head>
<body role="document">
<div id="navbar" class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html"><span><img src="_static/logo.png"></span>
</a>
<span class="navbar-text navbar-version pull-left"><b></b></span>
</div>
<div class="collapse navbar-collapse nav-collapse">
<ul class="nav navbar-nav">
<li><a href="https://github.com/sahib/rmlint">GitHub</a></li>
<li><a href="https://travis-ci.org/sahib/rmlint">Travis</a></li>
<li class="dropdown globaltoc-container">
<a role="button"
id="dLabelGlobalToc"
data-toggle="dropdown"
data-target="#"
href="index.html">Topics <b class="caret"></b></a>
<ul class="dropdown-menu globaltoc"
role="menu"
aria-labelledby="dLabelGlobalToc"><ul class="current">
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation</a><ul>
<li class="toctree-l2"><a class="reference internal" href="install.html#dependencies">Dependencies</a></li>
<li class="toctree-l2"><a class="reference internal" href="install.html#compilation">Compilation</a></li>
<li class="toctree-l2"><a class="reference internal" href="install.html#troubleshooting">Troubleshooting</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="tutorial.html">Gentle Guide to <code class="docutils literal"><span class="pre">rmlint</span></code></a><ul>
<li class="toctree-l2"><a class="reference internal" href="tutorial.html#beginner-examples">Beginner Examples</a></li>
<li class="toctree-l2"><a class="reference internal" href="tutorial.html#filtering-input-files">Filtering input files</a></li>
<li class="toctree-l2"><a class="reference internal" href="tutorial.html#outputs-formatters">Outputs & Formatters</a></li>
<li class="toctree-l2"><a class="reference internal" href="tutorial.html#paranoia-mode">Paranoia mode</a></li>
<li class="toctree-l2"><a class="reference internal" href="tutorial.html#original-detection-selection">Original detection / selection</a></li>
<li class="toctree-l2"><a class="reference internal" href="tutorial.html#finding-duplicate-directories">Finding duplicate directories</a></li>
<li class="toctree-l2"><a class="reference internal" href="tutorial.html#replaying-results">Replaying results</a></li>
<li class="toctree-l2"><a class="reference internal" href="tutorial.html#miscellaneous-options">Miscellaneous options</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="gui.html">Graphical user interface</a><ul>
<li class="toctree-l2"><a class="reference internal" href="gui.html#installation">Installation</a></li>
<li class="toctree-l2"><a class="reference internal" href="gui.html#usage">Usage</a></li>
<li class="toctree-l2"><a class="reference internal" href="gui.html#developers">Developers</a></li>
</ul>
</li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Cautions (or <em>why it’s hard to write a dupefinder</em>)</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#good-practice-when-deleting-duplicates">Good Practice when Deleting Duplicates</a></li>
<li class="toctree-l2"><a class="reference internal" href="#attributes-of-a-robust-duplicate-finder">Attributes of a Robust Duplicate Finder</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="faq.html#rmlint-finds-more-less-dupes-than-tool-x"><code class="docutils literal"><span class="pre">rmlint</span></code> finds more/less dupes than tool <code class="docutils literal"><span class="pre">X</span></code>!</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#can-you-implement-feature-x">Can you implement feature <code class="docutils literal"><span class="pre">X</span></code>?</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#i-forgot-to-add-some-options-before-running-on-a-large-dataset-do-i-need-to-re-run-it">I forgot to add some options before running on a large dataset. Do I need to re-run it?</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#i-have-a-very-large-number-of-files-and-i-run-out-of-memory-and-patience">I have a very large number of files and I run out of memory and patience.</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="developers.html">Developer’s Guide</a><ul>
<li class="toctree-l2"><a class="reference internal" href="developers.html#bugs">Bugs</a></li>
<li class="toctree-l2"><a class="reference internal" href="developers.html#philosophy">Philosophy</a></li>
<li class="toctree-l2"><a class="reference internal" href="developers.html#making-contributions">Making contributions</a></li>
<li class="toctree-l2"><a class="reference internal" href="developers.html#testsuite">Testsuite</a></li>
<li class="toctree-l2"><a class="reference internal" href="developers.html#buildsystem-helpers">Buildsystem Helpers</a></li>
<li class="toctree-l2"><a class="reference internal" href="developers.html#sourcecode-layout">Sourcecode layout</a></li>
<li class="toctree-l2"><a class="reference internal" href="developers.html#hashfunctions">Hashfunctions</a></li>
<li class="toctree-l2"><a class="reference internal" href="developers.html#optimizations">Optimizations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="translators.html">Translating <code class="docutils literal"><span class="pre">rmlint</span></code></a><ul>
<li class="toctree-l2"><a class="reference internal" href="translators.html#adding-new-languages">Adding new languages</a></li>
<li class="toctree-l2"><a class="reference internal" href="translators.html#updating-existing-languages">Updating existing languages</a></li>
<li class="toctree-l2"><a class="reference internal" href="translators.html#marking-new-strings-for-translations">Marking new strings for translations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="benchmarks.html">Benchmarks</a><ul>
<li class="toctree-l2"><a class="reference internal" href="benchmarks.html#user-benchmarks">User benchmarks</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="rmlint.1.html">Online-manpage of rmlint(1)</a><ul>
<li class="toctree-l2"><a class="reference internal" href="rmlint.1.html#find-duplicate-files-and-other-space-waste-efficiently">find duplicate files and other space waste efficiently</a></li>
</ul>
</li>
</ul>
</ul>
</li>
<li class="dropdown">
<a role="button"
id="dLabelLocalToc"
data-toggle="dropdown"
data-target="#"
href="#">Chapters <b class="caret"></b></a>
<ul class="dropdown-menu localtoc"
role="menu"
aria-labelledby="dLabelLocalToc"><ul>
<li><a class="reference internal" href="#">Cautions (or <em>why it’s hard to write a dupefinder</em>)</a><ul>
<li><a class="reference internal" href="#good-practice-when-deleting-duplicates">Good Practice when Deleting Duplicates</a><ul>
<li><a class="reference internal" href="#backup-your-data">Backup your data</a></li>
<li><a class="reference internal" href="#measure-twice-cut-once">Measure twice, cut once</a></li>
<li><a class="reference internal" href="#beware-of-unusual-filename-characters">Beware of unusual filename characters</a></li>
<li><a class="reference internal" href="#consider-safe-removal-options">Consider safe removal options</a></li>
</ul>
</li>
<li><a class="reference internal" href="#attributes-of-a-robust-duplicate-finder">Attributes of a Robust Duplicate Finder</a><ul>
<li><a class="reference internal" href="#traversal-robustness">Traversal Robustness</a></li>
<li><a class="reference internal" href="#collision-robustness">Collision Robustness</a></li>
<li><a class="reference internal" href="#unusual-characters-robustness">Unusual Characters Robustness</a></li>
<li><a class="reference internal" href="#seek-thrash-robustness"><em>“Seek Thrash”</em> Robustness</a></li>
<li><a class="reference internal" href="#memory-usage-robustness">Memory Usage Robustness</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</ul>
</li>
</ul>
<form class="navbar-form navbar-right" action="search.html" method="get">
<div class="form-group">
<input type="text" name="q" class="form-control" placeholder="Search" />
</div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12 content">
<div class="section" id="cautions-or-why-it-s-hard-to-write-a-dupefinder">
<h1>Cautions (or <em>why it’s hard to write a dupefinder</em>)<a class="headerlink" href="#cautions-or-why-it-s-hard-to-write-a-dupefinder" title="Permalink to this headline">¶</a></h1>
<p>This section covers good practice for safe duplicate removal. It is not intended to
be specifically related to <code class="docutils literal"><span class="pre">rmlint</span></code>. It includes general discussion on duplicate
detection and shows, by example, some of the traps that duplicate finders can fall into.
This section might not only be useful for developers of dupe finders, but also
educational for users that strive for best practices regarding deduplication.</p>
<div class="section" id="good-practice-when-deleting-duplicates">
<h2>Good Practice when Deleting Duplicates<a class="headerlink" href="#good-practice-when-deleting-duplicates" title="Permalink to this headline">¶</a></h2>
<div class="section" id="backup-your-data">
<h3>Backup your data<a class="headerlink" href="#backup-your-data" title="Permalink to this headline">¶</a></h3>
<p>There is a wise adage, <em>“if it’s not backed up, it’s not important”</em>. It’s just good
practice to keep your important data backed up. In particular, any time you are
contemplating doing major file reorganisations or deletions, that’s a good time to
make sure that your backups are up to date.</p>
<p>What about when you want to clean up your backups by deleting duplicate files from your
backup drive? Well as long as your duplicate file finder is reliable, you shouldn’t have
any problems. Consider replacing the duplicate with a link (hardlink, symlink or reflink)
to the original data. This still frees up the space, but makes it easier to find the file
if and when it comes time to restore files from backup.</p>
</div>
<div class="section" id="measure-twice-cut-once">
<h3>Measure twice, cut once<a class="headerlink" href="#measure-twice-cut-once" title="Permalink to this headline">¶</a></h3>
<p>This is a popular saying amongst builders; the same goes for your files. Do at least some
sort of sanity check on which files are going to be deleted. All duplicate file finders
(including <code class="docutils literal"><span class="pre">rmlint</span></code>) are capable of identifying false positives or more serious bugs.</p>
</div>
<div class="section" id="beware-of-unusual-filename-characters">
<h3>Beware of unusual filename characters<a class="headerlink" href="#beware-of-unusual-filename-characters" title="Permalink to this headline">¶</a></h3>
<p>Even a space in a filename is capable of <a class="reference external" href="https://github.com/MrMEEE/bumblebee-Old-and-abbandoned/issues/123">causing grief</a>. Make sure your file deletion command
(or the one used by your duplicate finder) has the filename properly escaped.</p>
</div>
<div class="section" id="consider-safe-removal-options">
<h3>Consider safe removal options<a class="headerlink" href="#consider-safe-removal-options" title="Permalink to this headline">¶</a></h3>
<p>Rather than deleting duplicates, consider moving them to a holding area or trash
folder. The <a class="reference external" href="http://github.com/andreafrancia/trash-cli">trash-cli utility</a> is one option for this. Alternatively if
using the <code class="docutils literal"><span class="pre">rmlint</span></code> shell script you can replace the <code class="docutils literal"><span class="pre">remove_cmd</span></code> section as
follows to move the files to <em>/tmp</em>:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>remove_cmd<span class="o">()</span> <span class="o">{</span>
<span class="nb">echo</span> <span class="s1">'Deleting:'</span> <span class="s2">"</span><span class="nv">$1</span><span class="s2">"</span>
<span class="k">if</span> original_check <span class="s2">"</span><span class="nv">$1</span><span class="s2">"</span> <span class="s2">"</span><span class="nv">$2</span><span class="s2">"</span><span class="p">;</span> <span class="k">then</span>
<span class="k">if</span> <span class="o">[</span> -z <span class="s2">"</span><span class="nv">$DO_DRY_RUN</span><span class="s2">"</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
<span class="c1"># was: rm -rf "$1"</span>
mv -p <span class="s2">"</span><span class="nv">$1</span><span class="s2">"</span> <span class="s2">"/tmp</span><span class="nv">$1</span><span class="s2">"</span>
<span class="k">fi</span>
<span class="k">fi</span>
<span class="o">}</span>
</pre></div>
</div>
<p>Another safe alternative, if your files are on a <code class="docutils literal"><span class="pre">btrfs</span></code> filesystem and you have linux
kernel 4.2 or higher, is to reflink the duplicate to the original. You can do this via
<code class="docutils literal"><span class="pre">cp</span> <span class="pre">--reflink</span></code> or using <code class="docutils literal"><span class="pre">rmlint</span> <span class="pre">--btrfs-clone</span></code>:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ cp --reflink<span class="o">=</span>always original duplicate <span class="c1"># deletes duplicate and replaces it with reflink copy of original</span>
$ rmlint --btrfs-clone original duplicate <span class="c1"># does and in-place clone</span>
</pre></div>
</div>
<p>If you pass <code class="docutils literal"><span class="pre">-c</span> <span class="pre">sh:link</span></code> to <code class="docutils literal"><span class="pre">rmlint</span></code>, it will even check for you if your
filesystem is capable of reflinks and emit the correct command conveniently.</p>
<p>The second option is actually safer because it verifies (via the kernel) that the files
are identical before creating the reflink. Also it does not change the mtime or other
metadata of the duplicate.</p>
<p>You might think hardlinking as a safe alternative to deletion, but in fact hardlinking
first deletes the duplicate and then creates a hardlink to the original in its place.
If your duplicate finder has found a false positive, it is possible that you may lose
your data.</p>
</div>
</div>
<div class="section" id="attributes-of-a-robust-duplicate-finder">
<h2>Attributes of a Robust Duplicate Finder<a class="headerlink" href="#attributes-of-a-robust-duplicate-finder" title="Permalink to this headline">¶</a></h2>
<p>(also known as <em>“Traps for young dupe finders”</em>)</p>
<div class="section" id="traversal-robustness">
<h3>Traversal Robustness<a class="headerlink" href="#traversal-robustness" title="Permalink to this headline">¶</a></h3>
<p><strong>Path Doubles</strong></p>
<p>One simple trap for a dupe finder is to not realise that it has reached the same file
via two different paths. This can happen due to user inputting overlapping paths to
traverse, or due to symlinks or other filesystem loops such as bind mounts.
Here’s a simple “path double” example trying to trick a duplicate file finder
by “accidentally” feeding it the same path twice. We’ll use
<a class="reference external" href="https://github.com/adrianlopezroche/fdupes">fdupes</a> for this example:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ mkdir dir
$ <span class="nb">echo</span> <span class="s2">"important"</span> > dir/file
$ fdupes -r --delete --noprompt dir dir
<span class="o">[</span>no output<span class="o">]</span>
$ ls dir
file
</pre></div>
</div>
<p>So far so good, <code class="docutils literal"><span class="pre">fdupes</span></code> didn’t fall for the trick. It has a check built-in which looks at
the files’ device and inode numbers, which automatically filters out path doubles.</p>
<p>Let’s try again using the -H option to find hardlinked duplicates:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ fdupes -r -H --delete --noprompt dir dir
<span class="o">[</span>+<span class="o">]</span> dir/file
<span class="o">[</span>-<span class="o">]</span> dir/file
$ ls -l dir/
total <span class="m">0</span>
</pre></div>
</div>
<p>Oh dear, our file is gone! The problem is that hardlinks share the same device and inode numbers,
so the inode check is turned off for this option.</p>
<p>Dupe finders <code class="docutils literal"><span class="pre">rdfind</span></code> and <code class="docutils literal"><span class="pre">dupd</span></code> can also be tricked with the right combination of settings:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ rdfind -removeidentinode <span class="nb">false</span> -deleteduplicates <span class="nb">true</span> a a
<span class="o">[</span>snip<span class="o">]</span>
Now deleting duplicates:
Deleted <span class="m">1</span> files.
$ ls -l dir/
total <span class="m">0</span>
$ dupd scan --path /home/foo/a --path /home/foo/a
Files scanned: <span class="m">2</span>
Total duplicates: <span class="m">2</span>
Run <span class="s1">'dupd report'</span> to list duplicates.
$ dupd report
Duplicate report from database /home/foo/.dupd_sqlite:
<span class="m">20</span> total bytes used by duplicates:
/home/foo/a/data
/home/foo/a/data
</pre></div>
</div>
<p><em>Solution:</em></p>
<p>For a duplicate finder to be able to find hardlinked duplicates, without also inadvertently
identifying a file as a duplicate or itself, a more sophisticated test is required. Path
doubles will always have:</p>
<ul class="simple">
<li>matching device and inode.</li>
<li>matching basename.</li>
<li>parent directories also have matching device and inode.</li>
</ul>
<p>That <strong>seems</strong> pretty fool-proof (see <code class="docutils literal"><span class="pre">rmlint</span></code> example below) but please file an issue
on our <a class="reference external" href="https://github.com/sahib/rmlint/issues">Issue Tracker</a> if you find an exception.</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ <span class="nb">echo</span> <span class="s2">"data"</span> > dir/file
$ <span class="c1"># rmlint with default settings:</span>
$ rmlint dir <span class="nv">dir</span>
<span class="o">==</span>> In total <span class="m">2</span> files, whereof <span class="m">0</span> are duplicates in <span class="m">0</span> groups.
<span class="o">==</span>> This equals <span class="m">0</span> B of duplicates which could be removed.
$
$ <span class="c1"># rmlint with hardlink duplicate detection enabled:</span>
$ rmlint --hardlinked dir <span class="nv">dir</span>
<span class="o">==</span>> In total <span class="m">2</span> files, whereof <span class="m">0</span> are duplicates in <span class="m">0</span> groups.
<span class="o">==</span>> This equals <span class="m">0</span> B of duplicates which could be removed.
$ ls dir
file
</pre></div>
</div>
<p><strong>Symlinks:</strong></p>
<p><em>“Ah but I’m not silly enough to enter the same path twice”</em> you say. Well maybe so, but
there are other ways that folder traversal can reach the same path twice, for example
via symbolic links:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ mkdir dir
$ <span class="nb">echo</span> <span class="s2">"important"</span> > dir/file
$ ln -s dir link
$ fdupes -r --delete --noprompt .
$ ls -l dir/
total <span class="m">0</span>
</pre></div>
</div>
<p>Symlinks can make a real mess out of filesystem traversal:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ mkdir dir
$ <span class="nb">cd</span> dir
$ ln -s . link
$ <span class="nb">cd</span> ..
$ <span class="nb">echo</span> <span class="s2">"data"</span> > dir/file
$ fdupes -rHs dir
dir/file
dir/link/file
dir/link/link/file
<span class="o">[</span>snip<span class="o">]</span>
dir/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/link/file
Set <span class="m">1</span> of <span class="m">1</span>, preserve files <span class="o">[</span><span class="m">1</span> - <span class="m">41</span>, all<span class="o">]</span>:
</pre></div>
</div>
<p><em>Solution:</em></p>
<p>During traversal, the duplicate finder should keep track of all folders visited (by device and inode number).
Don’t re-traverse folders that were already traversed.</p>
<p><strong>Hardlinks:</strong></p>
<p>Also as noted above, replacing duplicates with hardlinks can still end badly if there are
false positives. For example, using <code class="docutils literal"><span class="pre">rdfind</span></code>‘s the <code class="docutils literal"><span class="pre">-makehardlinks</span></code> option:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ <span class="nb">echo</span> <span class="s2">"data"</span> > dir/file
$ rdfind -removeidentinode <span class="nb">false</span> -makehardlinks <span class="nb">true</span> dir dir
<span class="o">[</span>snip<span class="o">]</span>
It seems like you have <span class="m">2</span> files that are not unique
Totally, <span class="m">5</span> b can be reduced.
Now making results file results.txt
Now making hard links.
failed to make hardlink dir/file to dir/file
$ ls -l dir
total <span class="m">0</span>
</pre></div>
</div>
<p><em>Solution:</em></p>
<p>Don’t find false positives. Check files are on same filesystem before trying to create hardlink.
Temporarily rename the duplicate before creating the hardlink and then deleting the renamed file.</p>
</div>
<div class="section" id="collision-robustness">
<h3>Collision Robustness<a class="headerlink" href="#collision-robustness" title="Permalink to this headline">¶</a></h3>
<p><strong>Duplicate detection by file hash</strong></p>
<p>If a duplicate finder uses file hashes to identify duplicates, there is a very
small risk that two different files have the same hash value. This is called a
<em>hash collision</em> and can result in the two files being falsely flagged as
duplicates.</p>
<p>Several duplicate finders use the popular MD5 Hash, which is 128 bits
long. With a 128-bit hash, if you have a million sets of same-size files, each set containing
a million different files, the chance of a hash collision is about
<code class="docutils literal"><span class="pre">0.000</span> <span class="pre">000</span> <span class="pre">000</span> <span class="pre">000</span> <span class="pre">000</span> <span class="pre">000</span> <span class="pre">147%</span></code>. To get a <code class="docutils literal"><span class="pre">0.1%</span></code> chance of a hash collision you would
need nine hundred thousand million (<span class="math">\(9\times10^{11}\)</span>) groups of (<span class="math">\(9\times10^{11}\)</span>) files each, or one group
of eight hundred thousand million million (<span class="math">\(8\times10^{17}\)</span>) files.</p>
<p>If someone had access to your files, and <em>wanted</em> to create a malicious duplicate, they
could potentially do something like this (based on <a class="reference external" href="http://web.archive.org/web/20071226014140/http://www.cits.rub.de/MD5Collisions/">http://web.archive.org/web/20071226014140/http://www.cits.rub.de/MD5Collisions/</a>):</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ mkdir <span class="nb">test</span> <span class="o">&&</span> <span class="nb">cd</span> <span class="nb">test</span>
$ <span class="c1"># get two different files with same md5 hash:</span>
$ wget http://web.archive.org/web/20071226014140/http://www.cits.rub.de/imperia/md/content/magnus/order.ps
$ wget http://web.archive.org/web/20071226014140/http://www.cits.rub.de/imperia/md/content/magnus/letter_of_rec.ps
$ md5sum * <span class="c1"># verify that they have the same md5sum</span>
a25f7f0b29ee0b3968c860738533a4b9 letter_of_rec.ps
a25f7f0b29ee0b3968c860738533a4b9 order.ps
$ sha1sum * <span class="c1"># verify that they are not actually the same</span>
07835fdd04c9afd283046bd30a362a6516b7e216 letter_of_rec.ps
3548db4d0af8fd2f1dbe02288575e8f9f539bfa6 order.ps
$ rmlint -a md5 . -o pretty <span class="c1"># run rmlint using md5 hash for duplicate file detection</span>
<span class="c1"># Duplicate(s):</span>
ls <span class="s1">'/home/foo/test/order.ps'</span>
rm <span class="s1">'/home/foo/test/letter_of_rec.ps'</span>
$ rmlint <span class="nb">test</span> -a sha1 -o summary <span class="c1"># run using sha1 hash</span>
<span class="o">==</span>> In total <span class="m">2</span> files, whereof <span class="m">0</span> are duplicates in <span class="m">0</span> groups.
</pre></div>
</div>
<p>If your intention was to free up space by hardlinking the duplicate to the original, you would end up with two
hardlinked files, one called <code class="docutils literal"><span class="pre">order.ps</span></code> and the other called
<code class="docutils literal"><span class="pre">letter_of_rec.ps</span></code>, both containing the contents of <code class="docutils literal"><span class="pre">order.ps</span></code>.</p>
<p><em>Solution:</em></p>
<p><code class="docutils literal"><span class="pre">fdupes</span></code> detects duplicates using MD5 Hashes, but eliminates the collision
risk by doing a byte-wise comparison of the duplicates detected. This means
each file is read twice, which can tend to slow things down.</p>
<p><code class="docutils literal"><span class="pre">dupd</span></code> uses direct file comparison, unless there are more than 3 files in a set of duplicates, in which
case it uses MD5 only.</p>
<p>If you use <code class="docutils literal"><span class="pre">rmlint</span></code>‘s <code class="docutils literal"><span class="pre">sha1</span></code> hash features, which features 160 bit output,
you need at least <span class="math">\(5.4\times10^{22}\)</span> files before you get a <span class="math">\(0.1\%\)</span>
probability of collision. <code class="docutils literal"><span class="pre">rmlint</span></code>‘s <code class="docutils literal"><span class="pre">-p</span></code> option uses <code class="docutils literal"><span class="pre">SHA512</span></code>
(<span class="math">\(5.2\times10^{75}\)</span> files for <span class="math">\(0.1\%\)</span> risk), while <code class="docutils literal"><span class="pre">rmlint</span></code>‘s
<code class="docutils literal"><span class="pre">-pp</span></code> option uses direct file comparison to eliminate the risk altogether.
Refer to the <a class="reference internal" href="benchmarks.html#benchmark-ref"><span class="std std-ref">Benchmarks</span></a> chapter for speed and memory overhead
implications.</p>
</div>
<div class="section" id="unusual-characters-robustness">
<h3>Unusual Characters Robustness<a class="headerlink" href="#unusual-characters-robustness" title="Permalink to this headline">¶</a></h3>
<p>Spaces, commas, nonprinting characters etc can all potentially trip up a duplicate finder or the subsequent file
deletion command. For example:</p>
<div class="highlight-bash"><div class="highlight"><pre><span></span>$ mkdir <span class="nb">test</span>
$ <span class="nb">echo</span> <span class="s2">"data"</span> > <span class="s1">'test/\t\r\"\b\f\\,.'</span>
$ cp test/<span class="se">\\</span>t<span class="se">\\</span>r<span class="se">\\\"\\</span>b<span class="se">\\</span>f<span class="se">\\\\\,</span>. test/copy <span class="c1"># even just copying filenames like this is ugly!</span>
$ ls -1 test/
copy
<span class="se">\t\r\"\b\f\\</span>,.
$ md5sum test/* <span class="c1"># md5's output gets a little bit mangled by the odd characters</span>
6137cde4893c59f76f005a8123d8e8e6 test/copy
<span class="se">\6</span>137cde4893c59f76f005a8123d8e8e6 test/<span class="se">\\</span>t<span class="se">\\</span>r<span class="se">\\</span><span class="s2">"\\b\\f\\\\,.</span>
$<span class="s2"> dupd scan --path /home/foo/test</span>
<span class="s2">SKIP (comma) [/home/foo/test/\t\r\"\b\f\\,.]</span>
<span class="s2">Files scanned: 1</span>
<span class="s2">Total duplicates: 0</span>
</pre></div>
</div>
<p><em>Solution:</em> Be careful!</p>
</div>
<div class="section" id="seek-thrash-robustness">
<h3><em>“Seek Thrash”</em> Robustness<a class="headerlink" href="#seek-thrash-robustness" title="Permalink to this headline">¶</a></h3>
<p>Duplicate finders use a range of strategies to find duplicates. It is common to reading and compare small increments
of potential duplicates. This avoids the need to read the whole file if the files differ in the first few megabytes,
so this can give a major speedup in some cases. However, in the case of hard disk drives, constantly reading small
increments from several files at the same time causes the hard drive head to have to jump around (“seek thrash”).</p>
<p>Here are some speed test results showing relative speed for scanning my <code class="docutils literal"><span class="pre">/usr</span></code> folder (on SSD) and an HDD copy of same.
The speed ratio gives an indication of how effectively the search algorithm manages disk seek overheads:</p>
<table border="1" class="docutils">
<colgroup>
<col width="26%" />
<col width="26%" />
<col width="34%" />
<col width="15%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Program</th>
<th class="head"><code class="docutils literal"><span class="pre">/usr</span></code> (SSD)</th>
<th class="head"><code class="docutils literal"><span class="pre">/mnt/usr</span></code> (HDD)</th>
<th class="head"><em>Ratio</em></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td><code class="docutils literal"><span class="pre">dupd</span></code></td>
<td>48s</td>
<td>1769s</td>
<td>36.9</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">fdupes</span></code></td>
<td>65s</td>
<td>486s</td>
<td>7.5</td>
</tr>
<tr class="row-even"><td><code class="docutils literal"><span class="pre">rmlint</span></code></td>
<td>38s</td>
<td>106s</td>
<td>2.8</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">rmlint</span> <span class="pre">-pp</span></code></td>
<td>40s</td>
<td>139s</td>
<td>3.5</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>Before each run, disk caches were cleared:</p>
<div class="last highlight-bash"><div class="highlight"><pre><span></span>$ sync <span class="o">&&</span> <span class="nb">echo</span> <span class="m">3</span> <span class="p">|</span> sudo tee /proc/sys/vm/drop_caches
</pre></div>
</div>
</div>
<p><em>Solution:</em></p>
<p>Achieving good speeds on HDD’s requires a balance between small file increments early on, then switching to
bigger file increments. Fiemap information (physical location of files on the disk) can be used to sort the
files into an order that reduces disk seek times.</p>
</div>
<div class="section" id="memory-usage-robustness">
<h3>Memory Usage Robustness<a class="headerlink" href="#memory-usage-robustness" title="Permalink to this headline">¶</a></h3>
<p>When scanning very large filesystems, duplicate finders may have to hold a large amount of information in
memory at the same time. Once this information exceeds the computers’ RAM, performance will suffer
significantly. <code class="docutils literal"><span class="pre">dupd</span></code> handles this quite nicely by storing a lot of the data in a sqlite database file,
although this may have a slight performance penalty due to disk read/write time to the database file.
<code class="docutils literal"><span class="pre">rmlint</span></code> uses a path tree structure to reduce the memory required to store all traversed paths.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<p class="pull-right">
<a href="#">Back to top</a>
<br/>
<div id="sourcelink">
<a href="_sources/cautions.rst.txt"
rel="nofollow">Source</a>
</div>
</p>
<p>
© Copyright 2014-2017, Christopher Pahl & Daniel Thomas.<br/>
Last updated on Jul 30, 2017.<br/>
</p>
</div>
</footer>
</body>
</html>
|