I would like to use Ruby to check if each of several thousand pairs of files contain identical information. Could someone point me in the right direction?
Probably the easiest way to compare two files is to use the diff command. The output will show you the differences between the two files. The < and > signs indicate whether the extra lines are in the first (<) or second (>) file provided as arguments.
The way to recognize a hard link is to look at the second field in a long file listing. If it's a "1", the file has no hard links. If it's 2 or greater (and not a directory), the same file exists somewhere else in the file system.
require 'fileutils'
FileUtils.compare_file('file1','file2')
returns true
if and only if files file1
and file2
are identical.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With