Grep in shell scripting



我想写一个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文件中的散列匹配的行。显然不是。

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

使用-f选项将完成工作

最新更新