我想查找给定名称的所有文件# find / -name myfile
,将它们与另一个给定文件进行比较/home/me/myCompareFile
,并输出文件是否相同。忽略空格会很好,但不是必需的。这可以从外壳中完成吗?谢谢
问问题
43 次
2 回答
2
您可以执行以下操作:
find . -name "t.c" | xargs -I % diff -q ../t.h % && echo "matches"
它将查找myFile
, 并为每个结果调用diff
与 进行比较myCompareFile
,并告诉您它是否不同(感谢-q
)
t.c
例如,我t.h
以当前目录为例:
% find . -name "t.c" | xargs -I % diff -q ./t.h % && echo "matches"
Files ./t.h and ./foo/t.c differ
Files ./t.h and ./t.c differ
% find . -name "t.c" | xargs -I % diff -q ./t.c % && echo "matches"
matches
甚至比&& echo "%matches"
:
% find . -name "t.c" | xargs -I % diff -qs ./t.c %
Files ./t.c and ./foo/t.c differ
Files ./t.c and ./t.c are identical
的-s
参数diff
是:
-s --report-identical-files
Report when two files are the same.
和-q
:
-q --brief
Output only whether files differ.
参考man diff
于 2013-06-22T22:29:33.937 回答
1
for file in $(find / -name myfile)
do
diff $file /home/me/myCompareFile
done
于 2013-06-22T22:29:26.563 回答