一个Python包,用于在混乱的数据集中搜索和删除重复的文件
deduplif的Python项目详细描述
重复性
在Python工具中删除重复的数据集。在
目录:
概述
deduplify
是一个Python命令行工具,它将在目录树中搜索重复的文件并选择性地删除它们。
它递归地为目标目录下的每个文件生成MD5哈希,将生成唯一和重复哈希的文件路径分组在一起。当删除重复的文件时,它会先删除目录树中最深的文件,最后保留最后一个文件。在
安装
{v3.8>已经开发了Python v3.8}的最低要求。在
从PyPI
首先,确保您的pip
版本是最新的。在
python -m pip install --upgrade pip
然后安装deduplify
。在
手动安装
首先克隆此存储库并将其更改为它。在
git clone https://github.com/Living-with-machines/deduplify.git
cd deduplify
现在运行安装脚本。
这将把任何需求和CLI工具安装到Python中$PATH
。在
python setup.py install
使用
deduplify
有3个命令:hash
,compare
和{
哈希文件
hash
命令将目标目录的路径作为参数。
它遍历这个目录树的结构,为所有文件生成MD5哈希,并输出两个JSON文件,可以使用--dupfile [-d]
和--unfile [-u]
标志覆盖它们的名称。在
一个JSON文件包含被认为是“唯一”的散列,因为只有一个文件路径生成了这个散列。 这个文件被组织成键是散列,值是生成散列的文件路径。在
第二个JSON文件包含被视为“重复”的哈希,因为多个文件路径生成了相同的哈希。 这个文件的组织方式是,键是散列,值是生成重复散列的文件路径的list。在
命令行用法:
usage: deduplify hash[-h][-c COUNT][-v][-d DUPFILE][-u UNFILE] dir positional arguments: dir Path to directory to begin search from optional arguments: -h, --help show this help message and exit -c COUNT, --count COUNT Number of threads to parallelise over. Default: 1 -v, --verbose Print logging messages to the console -d DUPFILE, --dupfile DUPFILE Destination file for duplicated hashes. Must be a JSON file. Default: duplicates.json -u UNFILE, --unfile UNFILE Destination file for unique hashes. Must be a JSON file. Default: uniques.json
比较文件
compare
命令读取运行hash
生成的重复文件的JSON文件,如果数据以不同的名称保存,则可以使用--infile [-i]
标志覆盖该文件的名称。
该命令运行一个检查,以测试文件路径的词干对于生成给定哈希的所有路径是否等效。
这表明该文件是真正的副本,因为它的名称和内容都匹配。
如果它们不匹配,这意味着相同的内容保存在两个不同的文件名下。
在这个场景中,会引发一个ValueError
,并要求用户手动调查这些文件。在
如果给定哈希的所有文件名都匹配,则最短的文件路径将从列表中删除,其余的则返回删除。
要删除文件,用户需要使用--purge
标志集运行compare
。在
为确保已删除所有重复文件,建议的工作流程如下:
deduplify hash target_dir # First pass at hashing files deduplify compare --purge # Delete duplicated files deduplify hash target_dir # Second pass at hashing files deduplify compare # Compare the filenames again. The code should return nothing to compare
命令行用法:
usage: deduplify compare [-h][-c COUNT][-v][-i INFILE][--purge] optional arguments: -h, --help show this help message and exit -c COUNT, --count COUNT Number of threads to parallelise over. Default: 1 -v, --verbose Print logging messages to the console -i INFILE, --infile INFILE Filename to analyse. Must be a JSON file. Default: duplicates.json --purge Deletes duplicated files. Default: False
清理
清除重复文件后,目标目录可能会留下空的子目录。
运行clean
命令将找到并删除这些空的子目录并将其删除。在
命令行用法:
usage: deduplify clean [-h][-c COUNT][-v] dir positional arguments: dir Path to directory to begin search from optional arguments: -h, --help show this help message and exit -c COUNT, --count COUNT Number of threads to parallelise over. Default: 1 -v, --verbose Print logging messages to the console
全局参数
以下标志可以传递给deduplify
的任何命令。在
--verbose [-v]
:该标志将把详细的输出打印到控制台,而不是将其保存到deduplify.log
文件中。在--count [-c]
:当使用更大的数据集时,deduplify
中的一些进程可以在多个线程上并行化。 为此,请将--count
标志与要并行处理的线程数(整数)一起包含在内。 这面旗帜将如果请求的线程多于主机上可用的CPU,则会出现错误。在
贡献
感谢您对deduplify
的贡献!:tada::闪闪发光的心脏:
要开始,请阅读我们的Code of Conduct和Contributing Guidelines。在
- 项目
标签: