まずはテストディレクトリとテストファイルを作成。
$ rm -fr ./tmp/rdfind_test_dir $ mkdir -p ./tmp/rdfind_test_dir $ for I in $(seq 0 1); do echo 1 > ./tmp/rdfind_test_dir/rdfind_test_file${I}; done;
rdfind に処理させたいディレクトリの素性は以下。
$ ls -li ./tmp/rdfind_test_dir total 32 241260 -rw-r--r-- 1 **** **** 2 Feb 10 21:32 rdfind_test_file0 241261 -rw-r--r-- 1 **** **** 2 Feb 10 21:32 rdfind_test_file1
まずは内容の同じファイルが既にハードリンク化されている状況を模倣するために rdfind を実行。結果を確認するとすべての同じ内容を持つファイルがハードリンク化されている事がわかる。
$ rdfind -makehardlinks true ./tmp/rdfind_test_dir Now scanning "./tmp/rdfind_test_dir", found 2 files. Now have 2 files in total. Removed 0 files due to nonunique device and inode. Now removing files with zero size from list...removed 0 files Total size is 4 bytes or 4 b Now sorting on size:removed 0 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 md5 checksum:removed 0 files from list.2 files left. It seems like you have 2 files that are not unique Totally, 2 b can be reduced. Now making results file results.txt Now making hard links. Making 1 links. $ ls -li ./tmp/rdfind_test_dir total 8 241261 -rw-r--r-- 2 **** **** 2 Feb 10 21:32 rdfind_test_file0 241261 -rw-r--r-- 2 **** **** 2 Feb 10 21:32 rdfind_test_file1
この状況下で同じ内容を持つファイルを追加する。
$ for I in $(seq 0 2); do echo 1 > ./tmp/rdfind_test_dir/rdfind_test_file${I}; done; $ ls -li ./tmp/rdfind_test_dir total 12 241261 -rw-r--r-- 2 **** **** 2 Feb 10 21:35 rdfind_test_file0 241261 -rw-r--r-- 2 **** **** 2 Feb 10 21:35 rdfind_test_file1 241260 -rw-r--r-- 1 **** **** 2 Feb 10 21:35 rdfind_test_file2
ここで rdfind を再実行して追加されたファイルが他のファイルへのハードリンクになるか確認する。結果は期待通り。
$ rdfind -makehardlinks true ./tmp/rdfind_test_dir Now scanning "./tmp/rdfind_test_dir", found 3 files. Now have 3 files in total. Removed 1 files due to nonunique device and inode. Now removing files with zero size from list...removed 0 files Total size is 4 bytes or 4 b Now sorting on size:removed 0 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 md5 checksum:removed 0 files from list.2 files left. It seems like you have 2 files that are not unique Totally, 2 b can be reduced. Now making results file results.txt Now making hard links. Making 1 links. $ ls -li ./tmp/rdfind_test_dir total 12 241261 -rw-r--r-- 3 **** **** 2 Feb 10 21:35 rdfind_test_file0 241261 -rw-r--r-- 3 **** **** 2 Feb 10 21:35 rdfind_test_file1 241261 -rw-r--r-- 3 **** **** 2 Feb 10 21:35 rdfind_test_file2