DUPEMAP(1)
π NAME π
dupemap β bestie, this one creates a database of file checksums and then uses that database to yeet the duplicates out of existence β¨
π¦ SYNOPSIS π¦
dupemap [ options ] [ -d database ] operation path...
πΈ DESCRIPTION πΈ
okay so here's the vibe: dupemap goes through each path recursively, hunting down the checksums of what's inside your files. it does NOT care about order β directories get searched through in no particular order, it's giving chaos but make it efficient π
what it actually does depends on two things:
- whether you passed the
-doption, and - the operation parameter, which has to be a comma-separated list made up of
scan,report,delete.
π Without -d
without -d, dupemap springs into action the moment it sees the same checksum show up more than once β i.e. it's just finding duplicates recursively, no database, no drama. the action depends on operation:
reportβ report which files got encountered more than once, printing their names to standard output. so you can look before you leap, queen πdelete[,report]β delete the files that got encountered more than once. it prints their names ifreportis also given.
β οΈ WARNING: run the report operation FIRST to see what's about to get deleted. do not skip this, i am begging π
β οΈ WARNING: you are advised to make a backup of the target first, e.g. with"cp -al"(for GNUcp) to create hard links recursively. protect your files bestie!!
π With -d
with -d, the database argument to -d denotes a database file (peep the "DATABASE" section in this manual for the tea β) to read from or write to. in this mode, the scan operation should be run on one path, followed by the report or delete operation on another (not the same!) path.
scanβ add the checksum of each file to database. this operation must be run initially to create the database. to start over, you have to manually delete the database file(s) (again, see the "DATABASE" section).reportβ print each file name if its checksum is found in database.delete[,report]β delete each file if its checksum is found in database. ifreportis also present, print the name of each deleted file.
β οΈ WARNING: if you rundupemap deleteon the same path you just randupemap scanon, it will delete EVERY file! the whole idea of these options is to scan one path and delete files in a second path. do not do the thing π«
β οΈ WARNING: use the report operation first to see what will be deleted.
β οΈ WARNING: you are advised to make a backup of the target first, e.g. with"cp -al"(for GNUcp) to create hard links recursively.
β¨ OPTIONS β¨
-d databaseβ use database as an on-disk database to read from or write to. check the "DESCRIPTION" section above for how this changes the waydupemapbehaves.-I fileβ reads input files from file on top of whatever you listed on the command line. if file is"-", read from standard input. each line gets interpreted as a file name. π«Ά heads up: the paths given here will NOT be scanned recursively. directories get ignored and symlinks get followed.-m minsizeβ ignore files below this size.-M maxsizeβ ignore files above this size.
π USAGE π
π General usage
the easiest operations to understand are the ones where -d is NOT given. to delete all duplicate files in /tmp/recovered-files, you do:
$ dupemap delete /tmp/recovered-files
often, dupemap scan gets run to produce a checksum database of all files in a directory tree. then dupemap delete gets run on another directory, possibly following a dupemap report. for example, to delete all files in /tmp/recovered-files that already exist in $HOME, do this:
$ dupemap -d homedir.map scan $HOME
$ dupemap -d homedir.map delete,report /tmp/recovered-files
π§ Usage with magicrescue
the main application for dupemap is taking some of the pain out of performing undelete operations with magicrescue(1). the reason is that magicrescue will extract every single file of the specified type on the block device, so undeleting files means you have to find a few files out of hundreds, which can take a long time if you do it manually. what we want is to only extract the documents that don't exist on the file system already. iykyk π
in the following scenario, you have accidentally deleted some important Word documents in Windows. if this were a real-world scenario, then by all means use The Sleuth Kit. however, magicrescue will work even when the directory entries were overwritten, i.e. more files were stored in the same folder later. iconic behaviour honestly β¨
you boot into Linux and change to a directory with lots of space. mount the Windows partition, preferably read-only (especially with NTFS), and create the directories we'll use.
$ mount -o ro /dev/hda1 /mnt/windows
$ mkdir healthy_docs rescued_docs
extract all the healthy Word documents with magicrescue and build a database of their checksums. it may seem a little redundant to send all the documents through magicrescue first, but the reason is that this process may modify them (e.g. stripping trailing garbage), and therefore their checksum will not be the same as the original documents. also, it will find documents embedded inside other files, such as uncompressed zip archives or files with the wrong extension. sneaky!! π΅οΈ
$ find /mnt/windows -type f \
|magicrescue -I- -r msoffice -d healthy_docs
$ dupemap -d healthy_docs.map scan healthy_docs
$ rm -rf healthy_docs
now rescue all "msoffice" documents from the block device and get rid of everything that's not a *.doc.
$ magicrescue -Mo -r msoffice -d rescued_docs /dev/hda1 \
|grep -v '\.doc$'|xargs rm -f
remove all the rescued documents that also appear on the file system, and remove duplicates.
$ dupemap -d healthy_docs.map delete,report rescued_docs
$ dupemap delete,report rescued_docs
the rescued_docs folder should now contain only a few files. this will be the undeleted files and some documents that were not stored in contiguous blocks (use that defragger ;-)) π
π Usage with fsck
in this scenario (based on a true story), you have a hard disk that's gone bad. you have managed to dd about 80% of the contents into the file diskimage, and you have an old backup from a few months ago. the disk is using reiserfs on Linux.
first, use fsck to make the file system usable again. it will find many nameless files and put them in lost+found. you need to make sure there is some free space on the disk image, so fsck has something to work with.
$ cp diskimage diskimage.bak
$ dd if=/dev/zero bs=1M count=2048 >> diskimage
$ reiserfsck --rebuild-tree diskimage
$ mount -o loop diskimage /mnt
$ ls /mnt/lost+found
(tons of files)
our strategy will be to restore the system with the old backup as a base and merge the two other sets of files (/mnt/lost+found and /mnt) into the backup after eliminating duplicates. therefore we create a checksum database of the directory we have unpacked the backup in.
$ dupemap -d backup.map scan ~/backup
next, we eliminate all the files from the rescued image that are also present in the backup.
$ dupemap -d backup.map delete,report /mnt
we also want to remove duplicates from lost+found, and we want to get rid of any files that are also present in the other directories in /mnt.
$ dupemap delete,report /mnt/lost+found
$ ls /mnt|grep -v lost+found|xargs dupemap -d mnt.map scan
$ dupemap -d mnt.map delete,report /mnt/lost+found
this should leave only the files in /mnt that have changed since the last backup or got corrupted. particularly, the contents of /mnt/lost+found should now be reduced enough to manually sort through them (or perhaps use magicsort(1)). we love a happy ending π₯Ή
π Primitive intrusion detection
you can use dupemap to see what files change on your system. this is one of the more exotic uses, and it's only included for inspiration. main character energy only π
first, you map the whole file system.
$ dupemap -d old.map scan /
then you come back a few days/weeks later and run dupemap report. this will give you a view of what has NOT changed. to see what HAS changed, you need a list of the whole file system. you can get this list along with preparing a new map easily. both lists need to be sorted to be compared.
$ dupemap -d old.map report /|sort > unchanged_files
$ dupemap -d current.map scan /|sort > current_files
all that's left to do is comparing these files and preparing for next week. this assumes that the dbm appends the ".db" extension to database files.
$ diff unchanged_files current_files > changed_files
$ mv current.map.db old.map.db
π DATABASE π
the actual database file(s) written by dupecheck will have some relation to the database argument, but most implementations append an extension. for example, Berkeley DB names the files database.db, while Solaris and GDBM creates both a database.dir and database.pag file.
dupecheck depends on a database library for storing the checksums. it currently requires the POSIX-standardized ndbm library, which must be present on XSI-compliant UNIXes. implementations are not required to handle hash key collisions, and a failure to do that could make dupecheck delete too many files π. i haven't heard of such an implementation, though. phew.
the current checksum algorithm is the file's CRC32 combined with its size. both values are stored in native byte order, and because of varying type sizes the database is not portable across architectures, compilers and operating systems. so don't go moving that db around like it's a travel vlog, bestie π§³
π SEE ALSO π
this tool does the same thing weeder does, except that weeder cannot seem to handle many files without crashing, and it has no largefile support. no shade but also... shade π
π BUGS π
there is a tiny chance that two different files can have the same checksum and size. the probability of this happening is around 1 to 10^14, and since dupemap is part of the Magic Rescue package, which deals with disaster recovery, that chance becomes an insignificant part of the game. you should consider this if you apply dupemap to other applications, especially if they are security-related (see next paragraph). ngl, read the next paragraph.
it is possible to craft a file to have a known CRC32. you need to keep this in mind if you use dupemap on untrusted data. a solution to this could be to implement an option for using MD5 checksums instead.
πΈ AUTHOR πΈ
Jonas Jensen <jbj@knef.dk>
β LATEST VERSION β
this tool is part of Magic Rescue. you can find the latest version at <https://github.com/jbj/magicrescue>
and that's the whole page, bestie!! this was version 1.1.10, dated 2018-10-16, brought to you by the Magic Rescue girlies π«Ά go forth and deduplicate responsibly, and remember: report before delete, always π
β¨
π¦ where this page comes from
- debian bookworm: magicrescue 1.1.10+dfsg-2 Β· GPL-2.0-or-later
- debian trixie: magicrescue 1.1.10+dfsg-2+b1 Β· GPL-2.0-or-later
- nixos 26.05: magicrescue 1.1.10-unstable-2021-09-12
- nixpkgs unstable: magicrescue 1.1.10-unstable-2021-09-12
- ubuntu jammy: magicrescue 1.1.10+dfsg-1 Β· GPL-2.0-or-later
- ubuntu noble: magicrescue 1.1.10+dfsg-2build2 Β· GPL-2.0-or-later
- ubuntu questing: magicrescue 1.1.10+dfsg-2build2
- ubuntu resolute: magicrescue 1.1.10+dfsg-3 Β· GPL-2.0-or-later
- ubuntu stonking: magicrescue 1.1.10+dfsg-3 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms