find ./ -type f -print0|xargs -0 md5sum |sort -k1,32|uniq -w32 -D
find "." -type f -printf "%i %p %s %t %M\n"
I have two unrelated scripts. I tried to connect them, but nothing works for me
The first prints something like
b1946ac92492d2347c6235b4d2611184 ./one/two/a.txt
b1946ac92492d2347c6235b4d2611184 ./some/c.txt
So we could continue by cutting off the first 34 characters, which leaves the paths, one per line. And if you have GNU xargs, that could then be processed with xargs -d '\n'
which could run e.g. ls
on them. Or find
.
$ find ./ -type f -print0|xargs -0 md5sum |sort |uniq -w32 -D |cut -c35- |xargs -d '\n' ls -ld
-rw-r--r-- 1 me me 6 Apr 12 22:38 ./one/two/a.txt
-rw-r--r-- 1 me me 6 Apr 12 22:38 ./some/c.txt
$ find ./ -type f -print0|xargs -0 md5sum |sort |uniq -w32 -D |cut -c35- |xargs -I{} -d '\n' find {} -printf "%i %p %s %t %M\n"
1706523 ./one/two/a.txt 6 Mon Apr 12 22:38:18.6494036350 2021 -rw-r--r--
1710394 ./some/c.txt 6 Mon Apr 12 22:38:24.8373114680 2021 -rw-r--r--
(sort -k1,32
would sort on the first and 32nd space-separated field, not on the first 32 characters. The hash is at the start of the string, so the default sort should work.)
Note that if you have filenames with newlines in them, xargs -d '\n'
won't do. But if that's an issue, you'll need more modifications since the output of md5sum
also changes when it encounters names like that. E.g. I get
$ md5sum $'new\nline'
\b1946ac92492d2347c6235b4d2611184 new\nline
with the leading backslash.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加