Computer >> 컴퓨터 >  >> 프로그래밍 >> Bash 프로그래밍

fdupes:Linux에서 중복 파일을 찾고 제거하기 위한 효율적인 명령줄 도구

대부분의 컴퓨터 사용자에게 중복 파일을 찾아 바꾸는 것은 일반적인 요구 사항입니다. 중복 파일을 찾아 제거하는 것은 시간과 인내가 필요한 지루한 작업입니다. 'fdupes 덕분에 컴퓨터가 GNU/Linux로 구동되는 경우 중복 파일을 찾는 것이 매우 쉽습니다. ' 유틸리티.

fdupes:Linux에서 중복 파일을 찾고 제거하기 위한 효율적인 명령줄 도구 Fdupes – Linux에서 중복 파일 찾기 및 삭제

fdupes가 무엇인가요?

프듀페 Adrian Lopez가 작성한 Linux 유틸리티입니다. C에서 MIT 라이선스에 따라 출시된 프로그래밍 언어입니다. 응용 프로그램은 지정된 디렉터리 및 하위 디렉터리 집합에서 중복 파일을 찾을 수 있습니다. Fdupes는 파일의 MD5 서명을 비교한 후 바이트 단위로 비교하여 중복 항목을 인식합니다. Fdupes와 함께 다양한 옵션을 전달하여 파일을 나열하고 삭제하고 중복 항목에 대한 하드링크로 교체할 수 있습니다.

비교는 다음 순서로 시작됩니다:

크기 비교> 부분적인 MD5 서명 비교> 전체 MD5 서명 비교> 바이트 대 바이트 비교 .

Linux에 fdupes 설치

Debian에서 다음 명령을 실행하면 최신 버전의 fdupes(fdupes 버전 1.51)를 쉽게 설치할 수 있습니다. Ubuntu와 같은 기반 시스템 및 리눅스 민트 .

$ sudo apt-get install fdupes

CentOS에서 /RHELFedora 기반 시스템의 경우 fdupes 패키지를 설치하려면 epel 저장소를 활성화해야 합니다.

# yum install fdupes
# dnf install fdupes [On Fedora 22 onwards]

참고 :기본 패키지 관리자 yum dnf로 대체됩니다. Fedora 22에서 앞으로…

fdupes 명령을 어떻게 사용하나요?

1. 시연을 위해 디렉토리(예:tecmint) 아래에 몇 개의 중복 파일을 만들어 보겠습니다. ) 간단하게:

$ mkdir /home/"$USER"/Desktop/tecmint && cd /home/"$USER"/Desktop/tecmint && for i in {1..15}; do echo "I Love Tecmint. Tecmint is a very nice community of Linux Users." > tecmint${i}.txt ; done

위 명령어를 실행한 후, ls 명령어를 이용하여 중복 파일이 생성되었는지 확인해보자.

$ ls -l
total 60
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint10.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint11.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint12.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint13.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint14.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint15.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint1.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint2.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint3.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint4.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint5.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint6.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint7.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint8.txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9.txt

위 스크립트는 15을 생성합니다. tecmint1.txt, tecmint2.txt…tecmint15.txt라는 파일과 모든 파일에는 동일한 데이터가 포함되어 있습니다. 즉,

"I Love Tecmint. Tecmint is a very nice community of Linux Users."

2. 이제 tecmint 폴더 내에서 중복 파일을 검색하세요. .

$ fdupes /home/$USER/Desktop/tecmint 
/home/tecmint/Desktop/tecmint/tecmint13.txt
/home/tecmint/Desktop/tecmint/tecmint8.txt
/home/tecmint/Desktop/tecmint/tecmint11.txt
/home/tecmint/Desktop/tecmint/tecmint3.txt
/home/tecmint/Desktop/tecmint/tecmint4.txt
/home/tecmint/Desktop/tecmint/tecmint6.txt
/home/tecmint/Desktop/tecmint/tecmint7.txt
/home/tecmint/Desktop/tecmint/tecmint9.txt
/home/tecmint/Desktop/tecmint/tecmint10.txt
/home/tecmint/Desktop/tecmint/tecmint2.txt
/home/tecmint/Desktop/tecmint/tecmint5.txt
/home/tecmint/Desktop/tecmint/tecmint14.txt
/home/tecmint/Desktop/tecmint/tecmint1.txt
/home/tecmint/Desktop/tecmint/tecmint15.txt
/home/tecmint/Desktop/tecmint/tecmint12.txt

3. -r을 사용하여 하위 디렉터리를 포함한 모든 디렉터리에서 중복 항목을 반복적으로 검색합니다. 옵션입니다.

모든 파일과 폴더를 반복적으로 검색합니다. 파일과 폴더 수에 따라 중복 항목을 검색하는 데 시간이 좀 걸립니다. 그동안 터미널에는 다음과 같은 전체 진행 상황이 표시됩니다.

$ fdupes -r /home
Progress [37780/54747] 69%

4. -S를 사용하여 폴더 내에서 발견된 중복 항목의 크기를 확인하세요. 옵션입니다.

$ fdupes -S /home/$USER/Desktop/tecmint
65 bytes each: 
/home/tecmint/Desktop/tecmint/tecmint13.txt
/home/tecmint/Desktop/tecmint/tecmint8.txt
/home/tecmint/Desktop/tecmint/tecmint11.txt
/home/tecmint/Desktop/tecmint/tecmint3.txt
/home/tecmint/Desktop/tecmint/tecmint4.txt
/home/tecmint/Desktop/tecmint/tecmint6.txt
/home/tecmint/Desktop/tecmint/tecmint7.txt
/home/tecmint/Desktop/tecmint/tecmint9.txt
/home/tecmint/Desktop/tecmint/tecmint10.txt
/home/tecmint/Desktop/tecmint/tecmint2.txt
/home/tecmint/Desktop/tecmint/tecmint5.txt
/home/tecmint/Desktop/tecmint/tecmint14.txt
/home/tecmint/Desktop/tecmint/tecmint1.txt
/home/tecmint/Desktop/tecmint/tecmint15.txt
/home/tecmint/Desktop/tecmint/tecmint12.txt

5. -S를 사용하면 모든 디렉터리와 하위 디렉터리에 대한 중복 파일의 크기를 확인할 수 있습니다. 및 -r 다음과 같은 옵션을 동시에 사용하세요:

$ fdupes -Sr /home/avi/Desktop/
65 bytes each: 
/home/tecmint/Desktop/tecmint/tecmint13.txt
/home/tecmint/Desktop/tecmint/tecmint8.txt
/home/tecmint/Desktop/tecmint/tecmint11.txt
/home/tecmint/Desktop/tecmint/tecmint3.txt
/home/tecmint/Desktop/tecmint/tecmint4.txt
/home/tecmint/Desktop/tecmint/tecmint6.txt
/home/tecmint/Desktop/tecmint/tecmint7.txt
/home/tecmint/Desktop/tecmint/tecmint9.txt
/home/tecmint/Desktop/tecmint/tecmint10.txt
/home/tecmint/Desktop/tecmint/tecmint2.txt
/home/tecmint/Desktop/tecmint/tecmint5.txt
/home/tecmint/Desktop/tecmint/tecmint14.txt
/home/tecmint/Desktop/tecmint/tecmint1.txt
/home/tecmint/Desktop/tecmint/tecmint15.txt
/home/tecmint/Desktop/tecmint/tecmint12.txt
107 bytes each:
/home/tecmint/Desktop/resume_files/r-csc.html
/home/tecmint/Desktop/resume_files/fc.html

6. 한 폴더 또는 모든 폴더를 반복적으로 검색하는 것 외에 필요에 따라 두 폴더 또는 세 폴더를 선택할 수 있습니다. 말할 것도 없이 -S 옵션을 사용할 수 있습니다. 및/또는 -r 필요한 경우.

$ fdupes /home/avi/Desktop/ /home/avi/Templates/

7. 복사본을 보존하면서 중복 파일을 삭제하려면 '-d' 옵션을 사용할 수 있습니다. . 이 옵션을 사용하는 동안에는 특별한 주의가 필요합니다. 그렇지 않으면 필요한 파일/데이터가 손실될 수 있으며 프로세스를 복구할 수 없다는 점에 유의하세요.

$ fdupes -d /home/$USER/Desktop/tecmint
[1] /home/tecmint/Desktop/tecmint/tecmint13.txt
[2] /home/tecmint/Desktop/tecmint/tecmint8.txt
[3] /home/tecmint/Desktop/tecmint/tecmint11.txt
[4] /home/tecmint/Desktop/tecmint/tecmint3.txt
[5] /home/tecmint/Desktop/tecmint/tecmint4.txt
[6] /home/tecmint/Desktop/tecmint/tecmint6.txt
[7] /home/tecmint/Desktop/tecmint/tecmint7.txt
[8] /home/tecmint/Desktop/tecmint/tecmint9.txt
[9] /home/tecmint/Desktop/tecmint/tecmint10.txt
[10] /home/tecmint/Desktop/tecmint/tecmint2.txt
[11] /home/tecmint/Desktop/tecmint/tecmint5.txt
[12] /home/tecmint/Desktop/tecmint/tecmint14.txt
[13] /home/tecmint/Desktop/tecmint/tecmint1.txt
[14] /home/tecmint/Desktop/tecmint/tecmint15.txt
[15] /home/tecmint/Desktop/tecmint/tecmint12.txt
Set 1 of 1, preserve files [1 - 15, all]: 

모든 중복 항목이 나열되고 하나씩, 특정 범위 또는 한 번에 모두 삭제하라는 메시지가 표시되는 것을 볼 수 있습니다. 특정 범위의 파일을 삭제하려면 아래와 같은 범위를 선택하면 됩니다.

Set 1 of 1, preserve files [1 - 15, all]: 2-15
 [-] /home/tecmint/Desktop/tecmint/tecmint13.txt
 [+] /home/tecmint/Desktop/tecmint/tecmint8.txt
 [-] /home/tecmint/Desktop/tecmint/tecmint11.txt
 [-] /home/tecmint/Desktop/tecmint/tecmint3.txt
 [-] /home/tecmint/Desktop/tecmint/tecmint4.txt
 [-] /home/tecmint/Desktop/tecmint/tecmint6.txt
 [-] /home/tecmint/Desktop/tecmint/tecmint7.txt
 [-] /home/tecmint/Desktop/tecmint/tecmint9.txt
 [-] /home/tecmint/Desktop/tecmint/tecmint10.txt
 [-] /home/tecmint/Desktop/tecmint/tecmint2.txt
 [-] /home/tecmint/Desktop/tecmint/tecmint5.txt
 [-] /home/tecmint/Desktop/tecmint/tecmint14.txt
 [-] /home/tecmint/Desktop/tecmint/tecmint1.txt
 [-] /home/tecmint/Desktop/tecmint/tecmint15.txt
 [-] /home/tecmint/Desktop/tecmint/tecmint12.txt

8. 안전 관점에서 'fdupes'의 출력을 인쇄하고 싶을 수도 있습니다. 파일을 저장한 다음 텍스트 파일을 확인하여 삭제할 파일을 결정하세요. 이렇게 하면 파일이 실수로 삭제될 가능성이 줄어듭니다. 다음을 수행할 수 있습니다:

$ fdupes -Sr /home > /home/fdupes.txt

참고 :'/home'을 바꿀 수 있습니다. 원하는 폴더로 '-r' 옵션도 사용하세요. 및 '-S' 재귀적으로 검색하고 인쇄 크기를 각각 검색하려는 경우

9. '-f' 옵션을 사용하여 각 일치 항목 집합에서 첫 번째 파일을 생략할 수 있습니다. .

먼저 디렉터리의 파일을 나열합니다.

$ ls -l /home/$USER/Desktop/tecmint
total 20
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9 (3rd copy).txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9 (4th copy).txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9 (another copy).txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9 (copy).txt
-rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9.txt

그런 다음 각 일치 항목 집합에서 첫 번째 파일을 생략합니다.

$ fdupes -f /home/$USER/Desktop/tecmint
/home/tecmint/Desktop/tecmint9 (copy).txt
/home/tecmint/Desktop/tecmint9 (3rd copy).txt
/home/tecmint/Desktop/tecmint9 (another copy).txt
/home/tecmint/Desktop/tecmint9 (4th copy).txt

10. 설치된 fdupes 버전을 확인하세요.

$ fdupes --version
fdupes 1.51

11. fdupes에 대한 도움이 필요하면 '-h' 스위치를 사용할 수 있습니다. .

$ fdupes -h
Usage: fdupes [options] DIRECTORY...
 -r --recurse for every directory given follow subdirectories
 encountered within
 -R --recurse: for each directory given after this option follow
 subdirectories encountered within (note the ':' at
 the end of the option, manpage for more details)
 -s --symlinks follow symlinks
 -H --hardlinks normally, when two or more files point to the same
 disk area they are treated as non-duplicates; this
 option will change this behavior
 -n --noempty exclude zero-length files from consideration
 -A --nohidden exclude hidden files from consideration
 -f --omitfirst omit the first file in each set of matches
 -1 --sameline list each set of matches on a single line
 -S --size show size of duplicate files
 -m --summarize summarize dupe information
 -q --quiet hide progress indicator
 -d --delete prompt user for files to preserve and delete all
 others; important: under particular circumstances,
 data may be lost when using this option together
 with -s or --symlinks, or when specifying a
 particular directory more than once; refer to the
 fdupes documentation for additional information
 -N --noprompt together with --delete, preserve the first file in
 each set of duplicates and delete the rest without
 prompting the user
 -v --version display fdupes version
 -h --help display this help message

이제 그게 전부입니다. 지금까지 Linux에서 중복 파일을 어떻게 찾고 삭제했는지 알려주세요. 또한 이 유틸리티에 대한 귀하의 의견을 알려주십시오. 아래 댓글 섹션에 소중한 피드백을 남겨주시고, 저희를 좋아요/공유해 주시고 널리 알려주세요.

저는 중복 파일을 제거하기 위해 fslint라는 또 다른 유틸리티를 개발 중입니다. 곧 게시될 예정이며 여러분도 좋아하실 것입니다.