From: "Peña, Botp" Date: 2008-10-25T14:59:42+09:00 Subject: Re: How to tell if two paths point to the same file? From: Nobuyoshi Nakada [mailto:nobu@ruby-lang.org] # At Sat, 25 Oct 2008 03:21:21 +0900, # Kenneth McDonald wrote in [ruby-talk:318516]: # > From the documentation, that seems to compare to different # files to # > see if they have the same content. Thanks for the # suggestion, though. # # It tells whether two files are an identical file, in other # words, same hardlinks. The doc is too terse? i think, Nobu, the method naming is misleading/clashing in File and FileUtils. there is File.identical? but there is also Fileutils#identical? wc is aliased to compare_file, wc is totally different w File.identical imho, there are already too many method names in ruby to remember. a lot almost having the same fxnality. it would be nice if file.identical just returns nil, or 1, or 0, where nil for different, 1 for same, and 0 for same self. comparison of File/fileutils identical follows.. ~$ qri file#identical? ------------------------------------------------------- File.identical?(file_1, file_2) => true or false -------------------------------------------------------- Returns true if the named files are identical. open("a", "w") {} p File.identical?("a", "a") #=> true p File.identical?("a", "./a") #=> true File.link("a", "b") p File.identical?("a", "b") #=> true File.symlink("a", "c") p File.identical?("a", "c") #=> true open("d", "w") {} p File.identical?("a", "d") #=> false ~$ qri fileutils#identical? --------------------------------------------------- FileUtils#identical? identical?(a, b) --------------------------------------------------- Alias for #compare_file Alias for #compare_file ~$ qri fileutils#compare_file ------------------------------------------------- FileUtils#compare_file compare_file(a, b) ------------------------------------------------- Returns true if the contents of a file A and a file B are identical. FileUtils.compare_file('somefile', 'somefile') #=> true FileUtils.compare_file('/bin/cp', '/bin/mv') #=> maybe false (also known as identical?, cmp)