How do I compare equality of two files in Ubuntu?

I have two large pkl files. I'm not interested in knowing the comparisons of the contents of two files (as we do for text files with diff, meld or vimdiff). I suspect that they are the same. Their size is equal. But if I want to get certain that they are the same, is there any comparison utility that outputs if they are the same or not?

1
задан 14 July 2020 в 19:44

2 ответа

You can use diff with -q option. From diff's manpage:

-q, --brief
       report only when files differ

Example usage:

$ diff -q a b
Files a and b differ

If the files are identical, there will be no output. However, if you want to report if they are identical as well, you can use -s option with -q.

From the same manpage:

-s, --report-identical-files
       report when two files are the same

Example usage:

$ diff -qs a b
Files a and b are identical
5
ответ дан 30 July 2020 в 22:07

I don't suppose this will be any faster than diff, but you could compare checksums of the files:

md5sum a b | awk '
    NR == 1 {sum_a = $1; next}
    {print ($1 == sum_a) ? "equal" : "different"}
'
3
ответ дан 30 July 2020 в 22:07

Другие вопросы по тегам:

Похожие вопросы: