UJP - rdfindで重複ファイルを探し出す

Life is fun and easy!

不正IP報告数

Okan Sensor
 
メイン
ログイン
ブログ カテゴリ一覧

  • カテゴリ コンピュータ の最新配信
  • RSS
  • RDF
  • ATOM

ブログ - rdfindで重複ファイルを探し出す

rdfindで重複ファイルを探し出す

カテゴリ : 
コンピュータ » クライアントソフト
ブロガー : 
ujpblog 2023/2/16 14:54
 大事なファイルを大事にしすぎてあちこちに保存していることがある.
 ということで,重複ファイルを探すrdfindを使ってみた.

 まずはBrewでパッケージを確認.
$ brew info rdfind🆑
==> rdfind: stable 1.5.0 (bottled)
Find duplicate files based on content (NOT file names)
https://rdfind.pauldreik.se/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/rdfind.rb
License: GPL-2.0-or-later
==> Dependencies
Required: nettle ✔
==> Analytics
install: 76 (30 days), 218 (90 days), 989 (365 days)
install-on-request: 76 (30 days), 218 (90 days), 989 (365 days)
build-error: 0 (30 days)
$
 インストール.
$ brew install rdfind🆑
Running `brew update --auto-update`...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
astgen                 guile-gnutls           papilo                 tl-expected
bwidget                juicefs                qdmr                   touca
cargo-make             kuttl                  rtx                    utftex
cargo-release          libaribcaption         soplex                 uvg266
conman                 libsolv                spek                   youplot
crfsuite               libzim                 stackql                zsh-autocomplete
geometry               micromamba             symlinks
gradle@7               opencl-clhpp-headers   tetra
==> New Casks
capslocknodelay                microsoft-defender             spotify4bigsur
coherence-x                    microsoft-office-businesspro   spybuster
copilot-for-xcode              microsoft-onenote              starnet-plus-plus
egnyte                         mochi-diffusion                teleport-connect
gpgfrontend                    monofocus                      ulbow
html-mangareader               nanosaur2
lotus                          pokemon-tcg-live

You have 34 outdated formulae and 1 outdated cask installed.
You can upgrade them with brew upgrade
or list them with brew outdated.

==> Fetching rdfind
==> Downloading https://ghcr.io/v2/homebrew/core/rdfind/manifests/1.5.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/rdfind/blobs/sha256:ab2c2353c248e27831c942
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:ab2c23
######################################################################## 100.0%
==> Pouring rdfind--1.5.0.monterey.bottle.tar.gz
🍺  /usr/local/Cellar/rdfind/1.5.0: 11 files, 159.9KB
==> Running `brew cleanup rdfind`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
$
 試験用に3つファイル,うち2つは中身が同じファイルを設置.
$ ls -la🆑
total 84
drwxr-xr-x   6 ujpadmin staff   192  2 16 14:25 .
drwxr-xr-x+ 55 ujpadmin staff  1760  2 16 14:24 ..
-rw-r--r--   1 ujpadmin staff 37304  2 16 14:21 file1.txt
-rw-r--r--   1 ujpadmin staff 37304  2 16 14:21 file2.txt
-rw-r--r--   1 ujpadmin staff     7  2 16 14:24 file3.txt
$
 実行してみる.
$ rdfind .🆑
Now scanning ".", found 3 files.
Now have 3 files in total.
Removed 0 files due to nonunique device and inode.
Total size is 74615 bytes or 73 KiB
Removed 1 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, 36 KiB can be reduced.
Now making results file results.txt
$
 まずファイルサイズが同一のファイルが2つある.
 最初のバイトをチェック.
 最後のバイトをチェック.
 SHA1のチェックサムで検証.

 重複ファイルを消せば36KB削減できるとのこと.

 結果がresults.txtファイルに保存されているので中身を確認
$ cat results.txt🆑
# Automatically generated
# duptype id depth size device inode priority name
DUPTYPE_FIRST_OCCURRENCE 1 0 37304 16777220 49496070 1 ./file1.txt
DUPTYPE_WITHIN_SAME_TREE -1 0 37304 16777220 49496282 1 ./file2.txt
# end of file
$
 SAME_TREEで絞り込む.
$ grep SAME_TREE results.txt🆑
DUPTYPE_WITHIN_SAME_TREE -1 0 37304 16777220 49496282 1 ./file2.txt
$
 ファイルパスを取り出す.
$ grep SAME_TREE results.txt |awk {'print $8'}🆑
./file2.txt
$
 これで,重複ファイルを削除できる.

 macOS用だとdupeGuruを使って重複読み込みした写真を検索して削除でも使ったdupeGuruを使うことができるけどね.

トラックバック


広告スペース
Google