有没有在一个目录十几万个文件里面搜索所有相同的文件方法 (已找到很多解决方案)

新手涉及到的教学或入门贴,推荐新手必看,版主维护
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#16

帖子 eexpress » 2007-11-08 11:39

直接都cp到一个目录。会提示你要覆盖的不。呵呵。笨。
● 鸣学
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

#17

帖子 BigSnake.NET » 2007-11-08 11:40

先统计文件大小

代码: 全选

du -ab *|sort
然后对有多个相同大小的做一次md5sum,再排序分类
然后对相同md5的再逐个diff
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
xiehuoli
帖子: 5941
注册时间: 2006-06-10 8:43
来自: 中国 CS

#18

帖子 xiehuoli » 2007-11-08 11:41

eexpress 写了:直接都cp到一个目录。会提示你要覆盖的不。呵呵。笨。
主要是里面的内容一样的,名字不同的
年轻没有失败! ! ! ! ! !
噢!有怪兽,有怪兽!
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#19

帖子 eexpress » 2007-11-08 11:43

说了。照片就有办法。
其他的。你md5去吧。搞死人的。
多半要建立数据索引。分几步走。
● 鸣学
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#20

帖子 bones7456 » 2007-11-08 14:34

BigSnake.NET 写了:先统计文件大小

代码: 全选

du -ab *|sort
然后对有多个相同大小的做一次md5sum,再排序分类
然后对相同md5的再逐个diff
相同md5的,还有diff的必要吗??
关注我的blog: ε==3
头像
xiehuoli
帖子: 5941
注册时间: 2006-06-10 8:43
来自: 中国 CS

#21

帖子 xiehuoli » 2007-11-08 16:11

收到通知,是文件名相同,内容相同的都要找出来
有没有什么好办法
年轻没有失败! ! ! ! ! !
噢!有怪兽,有怪兽!
头像
yiding_he
帖子: 2677
注册时间: 2006-10-25 18:10
来自: 长沙
联系:

#22

帖子 yiding_he » 2007-11-08 16:22

没有直接的命令可用,所以怕是要写程序了。那就有很多选择了。本人搞 java 的,不嫌弃的话给你弄一个,不过最简单的还是用 shell 编一个了,我却不会。
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#23

帖子 eexpress » 2007-11-08 16:28

简单而龌龊的方法要不。
一个for循环,把目录里面的文件全部加上.jpg后缀。开那 gthumb / gqview,使用只搜索同名文件的功能(不比较内容)。就可以找到文件。

你这要求特殊了,没写shell的好处。写程序,要建立列表。比较文件名,再比较内容。复杂。没边。
● 鸣学
头像
yiding_he
帖子: 2677
注册时间: 2006-10-25 18:10
来自: 长沙
联系:

#24

帖子 yiding_he » 2007-11-08 16:59

刚写的一个简单的工具,需要 java 1.5 以上。

加入你的文件都放在 /my/path 当中,则这样使用:

java -jar dfc.jar /my/path

执行完之后会在当前目录生成 result.txt。考虑到文件比较多,执行的过程中就去喝杯茶吧。
附件
dfc.jar
比较指定目录及子目录下的相同内容的文件的工具
(4.59 KiB) 已下载 137 次
头像
xiehuoli
帖子: 5941
注册时间: 2006-06-10 8:43
来自: 中国 CS

#25

帖子 xiehuoli » 2007-11-08 17:23

yiding_he
谢谢你
真是好人
年轻没有失败! ! ! ! ! !
噢!有怪兽,有怪兽!
头像
xiehuoli
帖子: 5941
注册时间: 2006-06-10 8:43
来自: 中国 CS

#26

帖子 xiehuoli » 2007-11-08 17:23

eexpress 写了:简单而龌龊的方法要不。
一个for循环,把目录里面的文件全部加上.jpg后缀。开那 gthumb / gqview,使用只搜索同名文件的功能(不比较内容)。就可以找到文件。

你这要求特殊了,没写shell的好处。写程序,要建立列表。比较文件名,再比较内容。复杂。没边。
会死人的哦
我这个本来就很麻烦的
没有别的好办法了骂?
哀!
谢谢大家
年轻没有失败! ! ! ! ! !
噢!有怪兽,有怪兽!
lisir
帖子: 1187
注册时间: 2006-04-29 14:54
来自: 山东
联系:

#27

帖子 lisir » 2007-11-08 21:29

相同文件名的可以用find,相同内容的,感觉还是上面那个先比较大小,再在相同大小的文件中比较这种思路要好的多,如果觉得md5sum慢,也可以尝试用od比较一下某部分的十六进制值,比如最后一行什么的。

这个思路也不知道行不行,我不太懂。


另外在freshmeat上看到的几个:
Dupseek finds and interactively removes duplicate files. It aims at maximum efficiency by keeping file reads to a minimum and is much better than other similar programs when dealing with groups of large files of the same size.
FDUPES is a program for identifying or deleting duplicate files residing within specified directories.
DupeFinder is a simple application for locating, moving, renaming, and deleting duplicate files in a directory structure. It's perfect both for users who haven't kept their hard drives very well organized and need to do some cleaning to free space, and for users who like to keep lots of backup copies of important data "just in case" something bad should happen.
weedit is a file duplicate scanner with database support. It uses CRC32, MD5, and file size to scan for duplicates. Files that are deleted are automatically removed from the database when a duplicate is found. It will only rescan files if the creation time or last write time change. It will only delete duplicated files if the parameter for deleting is used. The default setting is to report only.
whatpix is a Perl console application which finds (and optionally moves or deletes) duplicate files.
dupliFinder is a graphical tool that searches directories on your computer for duplicate files by checking and comparing the MD5 sum of each file. This means that the contents of the file are examined, not the filename. You then have the option of reviewing the duplicate files and then deleting them. It's great for finding duplicates in your MP3, image, or movie collections.
学会看置顶帖、精华帖。
学会使用搜索。
常见问题解答和发帖需知
头像
oneleaf
论坛管理员
帖子: 10441
注册时间: 2005-03-27 0:06
系统: Ubuntu 12.04

#28

帖子 oneleaf » 2007-11-09 16:38

不好意思,看到迟了

代码: 全选

#!/usr/bin/env python
#coding=utf-8
import binascii,os

filesizes={}
samefiles=[]
def filesize(path):
    if os.path.isdir(path):
        files=os.listdir(path)
        for file in files:
            filesize(path+"/"+file)
    else:
        size=os.path.getsize(path)
        if not filesizes.has_key(size):
             filesizes[size]=[]
        filesizes[size].append(path)

def filecrc(files):
    filecrcs={}
    for file in files:
        f=open(file,'r')
        crc = binascii.crc32(f.read())
        f.close()
        if not filecrcs.has_key(crc):
             filecrcs[crc]=[]
        filecrcs[crc].append(file)
    for filecrclist in filecrcs.values():
        if len(filecrclist)>1:
           samefiles.append(filecrclist)
            
if __name__ == "__main__":
    filesize("/home/oneleaf/test/")
    for sizesamefilelist in filesizes.values():
        if len(sizesamefilelist)>1:
            filecrc(sizesamefilelist)
    for samefile in samefiles:
        print "******* same files group **********"
        for file in samefile:
            print file

写了一个python的脚本,速度应该是比较快的,没有利用md5,直接利用了crc32,先检查出同样尺寸的文件,再计算crc32,得出相同的文件名列表。
头像
xiehuoli
帖子: 5941
注册时间: 2006-06-10 8:43
来自: 中国 CS

#29

帖子 xiehuoli » 2007-11-09 16:40

谢谢一叶阿
谢谢各位
我找到了一个软件
apt-get install fdupes
fdupes -h
可以用apt-cache search duplicate file
duplicate file -> 重复的文件
年轻没有失败! ! ! ! ! !
噢!有怪兽,有怪兽!
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#30

帖子 bones7456 » 2007-11-09 16:42

哇................!
关注我的blog: ε==3
回复