[태그:] 중복

  • mysql 중복 데이터 삭제

    매번 인터넷에서 찾다쓰다, 귀찮아 나중에 한번에 쓰기 위해 기록한다.

    아래 사이트를 참조했다.

    지운 후, rollback
    https://stackoverflow.com/questions/11011384/how-to-test-an-sql-update-statement-before-running-it

    inner join
    http://rapapa.net/?p=311

    중복 데이터 찾기
    http://ra2kstar.tistory.com/26

    사진을 database에 추가하면, 가끔? 중복 데이터가 생긴다.어디가 문제인지 모르겠으나, 중복되는 경로를 지우고 싶다.

    myphpadmin으로 임시 테이블을 작성하면 세션이 끝나면서 죽어버려 사용할 수 없다. 터미널로 연결하여 사용했다.

    #임시 테이블 작성..
    CREATE TEMPORARY TABLE if not EXISTS `toDelete` AS SELECT *, count(*) as `counter` from `picture` GROUP by `경로` HAVING `counter` >='2';
    
    #inner join으로 id중복되는 id를 찾음.
    select `picture`.* from `picture` inner join `toDelete` on `picture`.`id` = `toDelete`.`id` limit 10;
    
    #백업 시작..
    start transaction;
    
    #삭제.
    delete `picture`.* from `picture` inner join `toDelete` on `picture`.`id` = `toDelete`.`id`;
    
    #확인 후,
    commit
    
    #rollback
    

     

  • 중복파일 지우기

    다른 사이트에서 스크랩..

    시스템내 중복되어있는 파일을 정리하는데 가장쉽고 편리한 방법이 아닐까 합니다.
    정규표현식 써가면서 파일싸이즈 비교해서 뽑을 필요없이 아래 패키지 설치하나로 간단히 해결…
    참고
    https://code.google.com/p/fdupes/
    https://github.com/adrianlopezroche/fdupes

    -r 옵션은 하위디렉토리 까지 모두 검색
    -S 중복파일 사이즈 출력

    How to use fdupes?

    fdupes has a rich CLI:
    fdupes -r ./stuff > dupes.txt
    Then, deleting the duplicates was as easy as checking dupes.txt and deleting the offending directories. fdupes also can prompt you to delete the duplicates as you go along.

    fdupes -r /home/user > /home/user/duplicate.txt

    Output of the command goes in duplicate.txt.

    fdupes will compare the size and MD5 hash of the files to find duplicates.

    Unix: How to delete files listed in a file

    This is not very efficient, but will work if you need glob patterns (as in /var/www/*)

    for f in $(cat 1.txt) ; do
    rm $f
    done

    If you don’t have any patterns, you can use xargs like so:

    xargs rm < 1.txt