On 7/9/23 14:55, Robert Nichols wrote:
Also, if you run diff with the "-q" (--brief) option it
will simply report which files differ, stopping after the first mismatch in each file,
similar to what the cmp command would do.
For completeness, since the original topic was "does diff use short cuts?" and
I've not
seen it mentioned in the thread yet, diff *does* use a shortcut: it doesn't open the
files
at all if they are hardlinks to the same file, because the content is for sure equal.
Try this:
- go in a directory with a very big file (iso, mkv, qcow2, ...)
- ln myfile.iso myfile.iso2
- diff myfile.iso myfile.iso2
observe how the answer is immediate and the files are not opened at all
(strace shows that after two "stat"s, it exits without any "open").
There is a common practice to have a source dir, "cp -al", then work
on the second one (important: detach links when saving), finally do the diff,
it is very fast since the majority of files under comparison are
still hardlinked couples.
Regards.
--
Roberto Ragusa mail at robertoragusa.it