Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bulk check whether files have the same content

Tags:

file

ruby

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?

like image 558
Melanie Shebel Avatar asked Nov 18 '15 00:11

Melanie Shebel


People also ask

How do I check if two files have the same content in shell script?

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.

What is identification to know that the two files are hard linked with same file?

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.


1 Answers

require 'fileutils'

FileUtils.compare_file('file1','file2')

returns true if and only if files file1 and file2 are identical.

like image 122
Cary Swoveland Avatar answered Sep 27 '22 18:09

Cary Swoveland