我想找到给定名称# find / -name myfile
的所有文件,将它们与另一个给定文件/home/me/myCompareFile
进行比较,并输出文件是否相同。很高兴忽略空白,但没有必要。这可能是从shell做的吗?感谢
答案 0 :(得分: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
的{{1}}参数是:
diff
和 -s --report-identical-files
Report when two files are the same.
:
-q
cf -q --brief
Output only whether files differ.
答案 1 :(得分:1)
for file in $(find / -name myfile)
do
diff $file /home/me/myCompareFile
done