Linux

查找文件的所有唯一版本並將其分組

  • January 9, 2013

我有一個複雜的目錄結構,其中有很多foo.txt. 我想找到這個文件的所有副本,並按diff結果對它們進行分組,即

[type 1]
/bar2/sub1/foo.txt
/foobar/foo.txt

[type 2]
/bar2/sub1/foo.txt
/foobar/foo.txt

[type 3]
/sub3/sub4/sub5/foo.txt
...

像計算每個文件的 md5sum 並根據雜湊排序這樣簡單的事情怎麼樣。

md5deep -r . | sort

d921223ccbe759a632973962bc15a497  /root/.bash_history
dcac40478a92e87cd08a42a6425acea6  /root/testsrv/keys/04.pem
dcac40478a92e87cd08a42a6425acea6  /root/testsrv/keys/client2.crt
e12f5739f81b08c470f20890304bf53e  /root/.bashrc
e1b23db3d2293b142938c74649d9fa6a  /root/testsrv/list-crl
e4e2818e1ed11a951ed5da4e1a86885a  /root/testsrv/keys/revoke-test.pem
ee8bd2ea88220c877a62e22e36a02d20  /root/testsrv/keys/index.txt.attr
ee8bd2ea88220c877a62e22e36a02d20  /root/testsrv/keys/index.txt.attr.old

引用自:https://serverfault.com/questions/465482