dupe-files - Report duplicate or unique file contents
This document describes version 0.141 of dupe-files (from Perl distribution App-UniqFiles), released on 2023-02-06.
dupe-files --help (or -h, -?)
dupe-files --version (or -v)
dupe-files [--algorithm=str] [(--authoritative-dir=str)+|--authoritative-dirs-json=json|(-O=str)+] [--debug|--log-level=level|--quiet|--trace|--verbose] [--detail|-l] [--digest-args=s|--digest-args-json=json|-A=s] [--exclude-empty-files|-Z|--include-empty-files] [(--exclude-file-pattern=str)+|--exclude-file-patterns-json=json|(-X=str)+] [--format=name|--json] [--group-by-digest|--no-group-by-digest|--nogroup-by-digest] [(--include-file-pattern=str)+|--include-file-patterns-json=json|(-I=str)+] [--max-size=filesize] [--min-size=filesize] [--(no)naked-res] [--page-result[=program]|--view-result[=program]] [--recurse|-R|--no-recurse|--norecurse] [--report-duplicate=int] [--report-unique|-D|-a|-d|-u|--no-report-unique|--noreport-unique] [--show-count|-c|--count|--no-show-count|--noshow-count] [--show-digest] [--show-size] -- <files> ...
See examples in the "EXAMPLES" section.
This is a thin wrapper to uniq-files. It defaults report_unique to 0 and report_duplicate to 1.
report_unique
report_duplicate
* marks required options.
*
What algorithm is used to compute the digest of the content.
The default is to use md5. Some algorithms supported include crc32, sha1, sha256, as well as Digest to use Perl Digest which supports a lot of other algorithms, e.g. SHA-1, BLAKE2b.
md5
crc32
sha1
sha256
Digest
SHA-1
BLAKE2b
If set to '', 'none', or 'size', then digest will be set to file size. This means uniqueness will be determined solely from file size. This can be quicker but will generate a false positive when two files of the same size are deemed as duplicate even though their content may be different.
If set to 'name' then only name comparison will be performed. This of course can potentially generate lots of false positives, but in some cases you might want to compare filename for uniqueness.
Denote director(y|ies) where authoritative/"Original" copies are found.
Can be specified multiple times.
Denote director(y|ies) where authoritative/"Original" copies are found (JSON-encoded).
See --authoritative-dir.
--authoritative-dir
Show details (a.k.a. --show-digest, --show-size, --show-count).
See --digest-args.
--digest-args
Some Digest algorithms require arguments, you can pass them here.
(No description)
Filename (including path) regex patterns to include.
Filename (including path) regex patterns to include (JSON-encoded).
See --exclude-file-pattern.
--exclude-file-pattern
See --files.
--files
Can also be specified as the 1st command-line argument and onwards.
Sort files by its digest (or size, if not computing digest), separate each different digest.
Filename (including path) regex patterns to exclude.
Filename (including path) regex patterns to exclude (JSON-encoded).
See --include-file-pattern.
--include-file-pattern
Maximum file size to consider.
Minimum file size to consider.
If set to true, will recurse into subdirectories.
Whether to return duplicate items.
Default value:
1
Valid values:
[0,1,2,3]
Can be set to either 0, 1, 2, or 3.
If set to 0, duplicate items will not be returned.
If set to 1 (the default for dupe-files), will return all the the duplicate files. For example: file1 contains text 'a', file2 'b', file3 'a'. Then file1 and file3 will be returned.
dupe-files
file1
file2
file3
If set to 2 (the default for uniq-files), will only return the first of duplicate items. Continuing from previous example, only file1 will be returned because file2 is unique and file3 contains 'a' (already represented by file1). If one or more --authoritative-dir (-O) options are specified, files under these directories will be preferred.
uniq-files
-O
If set to 3, will return all but the first of duplicate items. Continuing from previous example: file3 will be returned. This is useful if you want to keep only one copy of the duplicate content. You can use the output of this routine to mv or rm. Similar to the previous case, if one or more --authoritative-dir (-O) options are specified, then files under these directories will not be listed if possible.
mv
rm
Whether to return unique items.
Whether to return each file content's number of occurence.
1 means the file content is only encountered once (unique), 2 means there is one duplicate, and so on.
Show the digest value (or the size, if not computing digest) for each file.
Note that this routine does not compute digest for files which have unique sizes, so they will show up as empty.
Show the size for each file.
Alias for --report-unique --report-duplicate=1 (report all files).
See --report-unique.
--report-unique
Alias for --noreport-unique --report-duplicate=3.
Alias for --noreport-unique --report-duplicate=1.
Alias for --report-unique --report-duplicate=0.
Shortcut for --log-level=debug.
Set log level.
By default, these log levels are available (in order of increasing level of importance, from least important to most): trace, debug, info, warn/warning, error, fatal. By default, the level is usually set to warn, which means that log statements with level info and less important levels will not be shown. To increase verbosity, choose info, debug, or trace.
trace
debug
info
warn
warning
error
fatal
For more details on log level and logging, as well as how new logging levels can be defined or existing ones modified, see Log::ger.
Shortcut for --log-level=error.
Shortcut for --log-level=trace.
Shortcut for --log-level=info.
Choose output format, e.g. json, text.
undef
Output can be displayed in multiple formats, and a suitable default format is chosen depending on the application and/or whether output destination is interactive terminal (i.e. whether output is piped). This option specifically chooses an output format.
Set output format to json.
When outputing as JSON, strip result envelope.
0
By default, when outputing as JSON, the full enveloped result is returned, e.g.:
[200,"OK",[1,2,3],{"func.extra"=>4}]
The reason is so you can get the status (1st element), status message (2nd element) as well as result metadata/extra result (4th element) instead of just the result (3rd element). However, sometimes you want just the result, e.g. when you want to pipe the result for more post-processing. In this case you can use --naked-res so you just get:
--naked-res
[1,2,3]
Filter output through a pager.
This option will pipe the output to a specified pager program. If pager program is not specified, a suitable default e.g. less is chosen.
less
View output using a viewer.
This option will first save the output to a temporary file, then open a viewer program to view the temporary file. If a viewer program is not chosen, a suitable default, e.g. the browser, is chosen.
Display help message and exit.
Display program's version and exit.
This script has shell tab completion capability with support for several shells.
To activate bash completion for this script, put:
complete -C dupe-files dupe-files
in your bash startup (e.g. ~/.bashrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is recommended, however, that you install modules using cpanm-shcompgen which can activate shell completion for scripts immediately.
To activate tcsh completion for this script, put:
complete dupe-files 'p/*/`dupe-files`/'
in your tcsh startup (e.g. ~/.tcshrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is also recommended to install shcompgen (see above).
For fish and zsh, install shcompgen as described above.
% dupe-files -lR *
Please visit the project's homepage at https://metacpan.org/release/App-UniqFiles.
Source repository is at https://github.com/perlancar/perl-App-UniqFiles.
perlancar <perlancar@cpan.org>
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
This software is copyright (c) 2023, 2022, 2020, 2019, 2017, 2015, 2014, 2012, 2011 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-UniqFiles
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
To install App::UniqFiles, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::UniqFiles
CPAN shell
perl -MCPAN -e shell install App::UniqFiles
For more information on module installation, please visit the detailed CPAN module installation guide.