같은 크기의 파일 비교해서 찾아내기...

oldbell의 이미지

aaaa.jpg
aaaa_thumb.jpg
....

aaaz_jpg
aaaz_thumb.jpg

jpg file과 thumbnail file이 같은 폴더에 있는데
어떤 경우에는 원본과 thumbnail 크기가 같은 경우가 있습니다.
갯수가 많아서(백만단위) find 나 shell script로 해당 파일을 찾아보려고 합니다.
좋은 방법이 없을까요?

JEEN의 이미지

Perl Wicked-Cool Script 에 그에 관련된 내용이 있습니다.

하나 사보셔도 되겠지만... 흠...

perl blah.pl [디렉토리] 하시면 됩니다.

문제가 될 경우 자삭하겠습니다(그 내용 그대로 퍼와서..;;)

#!/usr/bin/perl                                                                                                                                             
use strict;
use warnings;
use File::Find;
use Digest::MD5;
 
sub find_dups {
    my @dir_list = @_;
 
    if ($#dir_list < 0) {
        return undef;
    }
 
    my %files;
 
    find( sub {
        -f && push @{ $files{(stat(_))[7]}}, $File::Find::name
          }, @dir_list
        );
 
    my @result = ();
 
    foreach my $size (keys %files) {
        if ($#{$files{$size}} < 1) {
            next;
        }
        my %md5;
 
        foreach my $cur_file (@{$files{$size}}) {
            open my $fh, "<", $cur_file or next;
            binmode($fh);
            push @{$md5{
                Digest::MD5->new->addfile(*$fh)->hexdigest}
                }, $cur_file;
            close $fh;
        }
      foreach my $hash (keys %md5) {
            if ($#{$md5{$hash}} >= 1) {
                push @result, [@{$md5{$hash}}];
            }
        }
    }
    return @result;
}
 
my @dups = find_dups(@ARGV);
 
foreach my $cur_dup (@dups) {
    print "Duplicates\n";
    foreach my $cur_file (@{ $cur_dup }) {
	print "\t$cur_file\n";
    }
}

____________________
use perl;

use perl;

aero의 이미지

저라면 find, shell로 삽질하느니 그냥 Perl로 하겠습니다. 요즘 Perl 안 깔린 서버는 없죠? :)

search.pl

#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
 
sub process {
     if ( -f $_ and $_ =~ m/_thumb\.jpg$/o ) {
        my $org_file = $_;
        $org_file =~ s/_thumb//o;
        print "$_, $org_file are equal.\n" if -s $_ == -s $org_file;
     }
}
 
find( { wanted=>\&process }, $ARGV[0]);

사용법

perl search.pl ./directory_for_check
oldbell의 이미지

관심가져 주셔서 감사합니다.

인생의 무게를 느껴라. 아는 만큼 보이는게다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.