2013-03-03 90 views
0

我想写一个shell脚本,以消除重复的文件,但我得到了早期坚持...grep的在shell脚本

find $1 -type f -exec md5sum {} + > /tmp/$$ 
find $1 -type f -exec md5sum {} + | sort | awk '{print $1}' | uniq -d > \ 
    /tmp/$$.spec 

在这一点上,/ tmp目录/ PID持有MD5(空间)的文件名,并且/tmp/PID.spec保存重复的散列。如何在/ tmp/PID中搜索每个重复的散列?

cat /tmp/$$ | grep /tmp/$$.spec 

没有返回结果,但我认为这会去一行一行通过我的完整文件,并只返回与代表.spec文件的散列匹配线。显然不是。

+0

可能重复:在UNIX中取出相同的文件(http://stackoverflow.com/questions/2400574/remove-identical-files- in-unix/2400784)和[在终端中检查重复?](http://stackoverflow.com/questions/621708/checking-duplicates-in-terminal) – 2013-03-03 09:34:02

回答

4

grep -f /tmp/$$.spec /tmp/$$

使用-f选项将做的工作

+0

谢谢:)。你真棒。 – SetSlapShot 2013-03-03 03:37:00