리눅스 파일에 동일한 콘텐츠를 식별하는 방법

때때로 파일의 복사본 디스크 공간의 엄청난 낭비에 해당하고 파일을 업데이트 할 때 문제가 발생합니다. 다음 명령은이 문서의 여섯 식별하는 데 사용됩니다.

최근 포스트에서 우리는 보았다 확인하고 파일을 하드 링크를 찾는 방법 (즉, 동일한 하드 디스크와 콘텐츠 공유 아이 노드를 가리킨). 이 글에서, 우리는 같은 찾아 볼 것이다 내용을 하지만, 명령 파일에 연결되지.

그들은 로컬 파일 시스템에 저장된 여러 개의 파일을 사용하지만, 추가 하드 디스크 공간을 차지하지 않기 때문에 하드 링크는 유용합니다. 당신이 고통을 유발의 위험이있을 것 파일을 업데이트 할 때 다른 한편으로는, 파일의 때로는 사본 디스크 공간의 엄청난 낭비에 해당합니다. 이 글에서, 우리는이 파일을 식별하는 다양한 방법 볼 것이다.

diff 명령은 파일을 비교로

두 파일을 비교 수있는 가장 쉬운 방법은 사용하는 것입니다 diff명령을 사용합니다. 출력 파일에서 다른 나타납니다. <그리고 >기호를 통해 전달 된 매개 변수를 나타내는 경우 (첫번째 <) 또는 초 ( >파일의 텍스트 추가 라인이있는 경우). 이 예에서,에서 backup.html텍스트의 추가 라인.

$ diff index.html backup.html
2438a2439,2441
> <pre>
> That's all there is to report.
> </pre>
复制代码

경우 diff같은 두 개의 파일을 나타냅니다에는 출력이 없습니다.

$ diff home.html index.html
$
复制代码

diff 이 두 파일을 비교할 수 있으며 비교하는 파일을 지정해야합니다 유일한 단점은,이 게시물은 당신을 위해 몇 가지 명령을 여러 중복 파일에서 찾을 수 있습니다.

사용 검사

cksum(체크섬) 체크섬을 계산하는 명령 파일. 체크섬 긴 번호 (예컨대 2,819,078,353,228,029) 수학 환원로 텍스트 콘텐츠이다. 체크섬은 완전히 독특한 아니라, 파일 체크섬의 다른 내용하지만 같은 최소한의 가능성이 있지만.

$ cksum *.html
2819078353 228029 backup.html
4073570409 227985 home.html
4073570409 227985 index.html
复制代码

위의 예에서, 당신은 볼과 같은이 기본이 될 수있는 방법 같은 두 번째와 세 번째 파일을 생성 확인할 수 있습니다.

find 명령을 사용하여

그동안 find중복 파일을 찾을 수있는 옵션이 없습니다 명령, 아직 이름이나 유형으로 파일을 찾아 실행하는 데 사용할 수있는 cksum명령을 사용합니다. 예를 들면 :

$ find . -name "*.html" -exec cksum {} \;
4073570409 227985 ./home.html
2819078353 228029 ./backup.html
4073570409 227985 ./index.html
复制代码

fslint 명령을 사용하여

fslint명령은 특히 중복 파일을 찾을 수 있습니다. 우리는 그것을 시작 위치를 준합니다. 그것은 완료하는 데 시간이 걸릴 문서의 상당수를 통과 할 필요가있는 경우. 이 중복 파일을 나열하는 방법을 알 수 및 빈 디렉토리 나쁜 ID와 같은 다른 문제를 찾습니다.

$ fslint .
-----------------------------------file name lint
-------------------------------Invalid utf8 names
-----------------------------------file case lint
----------------------------------DUPlicate files   <==
home.html
index.html
-----------------------------------Dangling links
--------------------redundant characters in links
------------------------------------suspect links
--------------------------------Empty Directories
./.gnupg
----------------------------------Temporary Files
----------------------duplicate/conflicting Names
------------------------------------------Bad ids
-------------------------Non Stripped executables
复制代码

당신은 당신의 시스템에 설치해야 할 수도 있습니다 fslint. 당신은 또한 당신의 명령 검색 경로에 추가해야 할 수도 있습니다 :

$ export PATH=$PATH:/usr/share/fslint/fslint
复制代码

rdfind 명령을 사용하여

rdfind명령은 중복 (동일한 콘텐츠) 파일을 찾을 것입니다. 그 이름은 "반복 검색"을 의미하며, 그것은 원래 어떤 파일을 결정하기 위해 파일 날짜를 기준으로 할 수 있습니다 - 당신이 사본을 삭제하도록 선택할 때 새로운 파일을 제거하기 때문에 유용합니다.

$ rdfind ~
Now scanning "/home/shark", found 12 files.
Now have 12 files in total.
Removed 1 files due to nonunique device and inode.
Total size is 699498 bytes or 683 KiB
Removed 9 files due to unique sizes from list.2 files left.
Now eliminating candidates based on first bytes:removed 0 files from list.2 files left.
Now eliminating candidates based on last bytes:removed 0 files from list.2 files left.
Now eliminating candidates based on sha1 checksum:removed 0 files from list.2 files left.
It seems like you have 2 files that are not unique
Totally, 223 KiB can be reduced.
Now making results file results.txt
复制代码

당신이 할 수있는 dryrun이 명령 모드를 실행 (즉, 또 다른 변화 보고서가 만들어 질 수있다).

$ rdfind -dryrun true ~
(DRYRUN MODE) Now scanning "/home/shark", found 12 files.
(DRYRUN MODE) Now have 12 files in total.
(DRYRUN MODE) Removed 1 files due to nonunique device and inode.
(DRYRUN MODE) Total size is 699352 bytes or 683 KiB
Removed 9 files due to unique sizes from list.2 files left.
(DRYRUN MODE) Now eliminating candidates based on first bytes:removed 0 files from list.2 files left.
(DRYRUN MODE) Now eliminating candidates based on last bytes:removed 0 files from list.2 files left.
(DRYRUN MODE) Now eliminating candidates based on sha1 checksum:removed 0 files from list.2 files left.
(DRYRUN MODE) It seems like you have 2 files that are not unique
(DRYRUN MODE) Totally, 223 KiB can be reduced.
(DRYRUN MODE) Now making results file results.txt
复制代码

rdfind명령은 빈 문서를 (무시 유사한 제공 -ignoreempty)과 심볼릭 링크를 (따라 -followsymlinks) 함수를. 에 대한 설명은 man 페이지를 확인하십시오.

-ignoreempty       ignore empty files
-minsize        ignore files smaller than speficied size
-followsymlinks     follow symbolic links
-removeidentinode   remove files referring to identical inode
-checksum       identify checksum type to be used
-deterministic      determiness how to sort files
-makesymlinks       turn duplicate files into symbolic links
-makehardlinks      replace duplicate files with hard links
-makeresultsfile    create a results file in the current directory
-outputname     provide name for results file
-deleteduplicates   delete/unlink duplicate files
-sleep          set sleep time between reading files (milliseconds)
-n, -dryrun     display what would have been done, but don't do it
复制代码

참고 rdfind명령을 제공하는 -deleteduplicates true복사 설정을 삭제하는 옵션을 선택합니다. 나는 명령 구문에 대한이 작은 문제가 당신을 성가 시게하지 바랍니다. ;-)

$ rdfind -deleteduplicates true .
...
Deleted 1 files.    <==
复制代码

당신은 아마 당신의 시스템에 설치해야합니다 rdfind명령. 그것은 좋은 생각이 될 수도 있습니다 사용하는 방법에 익숙해을 테스트합니다.

명령 fdupes를 사용하여

fdupes명령은 쉽게 중복 파일을 식별 할 수 있습니다. 반복에 - 예를 들어, 그것은 또한 유용한 옵션을 제공합니다 -r. 이 경우, 그룹화 된 파일을 복제하고 싶습니다 :

$ fdupes ~
/home/shs/UPGRADE
/home/shs/mytwin

/home/shs/lp.txt
/home/shs/lp.man

/home/shs/penguin.png
/home/shs/penguin0.png
/home/shs/hideme.png
复制代码

이것은 많은 중복 파일이 중요 (사용자 것을 반복 주 사용의 예입니다 .bashrc.profile파일)을 삭제하지 않아야합니다.

# fdupes -r /home
/home/shark/home.html
/home/shark/index.html

/home/dory/.bashrc
/home/eel/.bashrc

/home/nemo/.profile
/home/dory/.profile
/home/shark/.profile

/home/nemo/tryme
/home/shs/tryme

/home/shs/arrow.png
/home/shs/PNGs/arrow.png

/home/shs/11/files_11.zip
/home/shs/ERIC/file_11.zip

/home/shs/penguin0.jpg
/home/shs/PNGs/penguin.jpg
/home/shs/PNGs/penguin0.jpg

/home/shs/Sandra_rotated.png
/home/shs/PNGs/Sandra_rotated.png
复制代码

fdupe대부분의 옵션은 다음과 같이 명령은 다음과 같습니다. 사용 fdupes -h명령을 하시거나 자세한 사항은 매뉴얼 페이지를 참조하십시오.

-r --recurse     recurse
-R --recurse:    recurse through specified directories
-s --symlinks    follow symlinked directories
-H --hardlinks   treat hard links as duplicates
-n --noempty     ignore empty files
-f --omitfirst   omit the first file in each set of matches
-A --nohidden    ignore hidden files
-1 --sameline    list matches on a single line
-S --size        show size of duplicate files
-m --summarize   summarize duplicate files information
-q --quiet       hide progress indicator
-d --delete      prompt user for files to preserve
-N --noprompt    when used with --delete, preserve the first file in set
-I --immediate   delete duplicates as they are encountered
-p --permissions don't soncider files with different owner/group or
                 permission bits as duplicates
-o --order=WORD  order files according to specification
-i --reverse     reverse order while sorting
-v --version     display fdupes version
-h --help        displays help
复制代码

fdupes 또 다른 명령을 설치하고 많은 옵션의 명령에 익숙해 질 시간에 사용할 필요가있다.

개요

리눅스 시스템은 위치 등을 제공하는 중복 파일을 처리하기위한 옵션을 사용하면 발견 한 경우 (잠재적으로) 좋은 도구의 일련의 중복 파일을 제거 할 수 있습니다, 당신은 검색 영역을 지정할 수 있습니다합니다.


를 통해 : www.networkworld.com/article/339...

저자 : 산드라 헨리 - 스토커 주제 : lujun9972의 번역기 : tomjlw 교정 : wxy에

로부터이 문서 LCTT 원래 컴파일러, 리눅스 중국은 자랑스럽게

HTTPS : //juejin.im/post/5cfe74985188254ee433c032 재현

추천

출처blog.csdn.net/weixin_34101784/article/details/93183697