Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

File.identical?

File.identical?(file_1, file_2) → true or false

Returns true if the named files are identical.

file_1 and file_2 can be an IO object.

Example
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
See also .grpowned? .join .ftype .lchmod also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1