Skip to main content

remdups - remove duplicate files

Project description


Roland Puntaier



See LICENSE file


remdups generates a script to

  • remove duplicate files

  • copy files from another directory to this one, ignoring duplicates

  • move files from another directory to this one, ignoring duplicates

The resulting script should be further inspected before executing it in your shell.


  1. Optional. You can choose one or more source+hashing methods, via e.g.:

    cat > .remdups_c.sha512
    cat > .remdups_e.md5

    All of .remdups_{c,b,d,e,n}.{sha512, sha384, sha256, sha224, sha1, md5} contribute to the final hash. If you don’t make such a file, the default is:


    {‘c’: ‘content’, ‘b’: ‘block’, ‘d’: ‘date’, ‘e’: ‘exif’, ‘n’: ‘name’}

  1. Create the hash file by either of (can take a long time):

    remdups update
    remdups update <fromdir>

    The hashes are added to all .remdups_x.y. To rehash all files:

    rm .remdups_*
  2. Make a script with rm, mv, cp commands. It can be repeated with different options until the script is good.

    $remdups rm -s $remdups cp -s script.bat #if you used <fromdir> $remdups mv -s #if you used <fromdir>

    If the file ends in .sh, cp is used and the file names are in linux format. This is usable also on Windows with MSYS, MSYS2 and CYGWIN.

    If the file ends in .bat, Windows commands are used.

    If the file ends in .py, python functions are used.

  3. Inspect the script and go back to 2., if necessary. Changes to the script can also be done with the editor.

  4. execute script


Alternatively you can use remdups from your own python script, or interactively from a python prompt.


  • Directly from PyPi:

$ pip install remdups
  • From github: Clone, change to the directory and do

$ python install
  • If you plan to extend this tool

    • fork on github

    • clone from your fork to you PC

    • do an editable install

    $ pip install -e .
    • test after change and bring coverage to 100%

    $ py.test --cov --cov-report term-missing
    • consider sharing changes useful for others (github pull request).

Command Line

The following is in addition to the help given with:

remdups --help

The sources for the hashes can be:

{'c': 'content', 'b': 'block', 'd': 'date', 'e': 'exif', 'n': 'name'}

Don’t include n, because same files with different names cannot be found. c is the best.

Do e.g:

cat > .remdups_b.sha512
cat > .remdups_c.sha256

Fill the hash files from the current directory:

remdups update

Or fill the hash files from another directory:

remdups update <fromdir>

In the latter case the paths in the hash files will have a // or \\ to mark the start for the new relatives paths in a subsequent mv or cp command.

Once the hash files are filled create the script. It depend on the extension used:

remdups <command> -s <options>
remdups <command> -s script.bat <options>
remdups <command> -s <options>

command can be rm, cp, mv. There is also dupsof and dupsoftail, but they don’t take a --script, but print the output.

--keep-in, --keep-out and --comment-out will remove different files of a duplicate group. --safe will do a byte-wise comparison, before creating the script. That takes longer.

cp and mv also take --sort: In this case the tree is not recreated, but the files are sorted to the provided tree structure using the file modification date. See


With your own python script you can load the file for hashing and use the loaded content immediately to create the new file, if not duplicate.

from remdups import *
hasher = Hasher()
allduplicates = []
for filename,duplicates,content in hasher.foreachcontent('.'):
  if duplicates:
    assert content!=[] #some .remdups_ must be with (c)ontent
    nfilename = 'afilehere'
    with open(nfilename,'wb') as nf:
      for buf in content:
    shutil.copystat(filename, nfilename)

foreachcontent() uses scandir(), but does not add duplicate files to the .remdup_ files.

for f in hasher.scandir(otherdir,filter=['*.jpg'],exclude=['**/old/*']):
   duplicates = hasher.duplicates(f)
   yield (f,duplicates,kw['content'])
   if duplicates:

If you don’t want to keep the content, don’t provide a [] for content in scandir. scandir() will hash all files not yet in the .remdup_ files and will return the file name.

This code resorts a tree by hashing and creating a copy, if not duplicate.

import os
import remdups
with open('.remdups_c.sha256','w'): pass

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release. See tutorial on generating distribution archives.

Built Distribution

remdups-1.3.1-py3-none-any.whl (16.6 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page