Skip to content

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

class method

File.link

File.link(old_name, new_name) → 0

Creates a new name for an existing file using a hard link. Will not overwrite new_name if it already exists (raising a subclass of SystemCallError). Not available on all platforms.

Example
File.link("testfile", ".testfile")   #=> 0
IO.readlines(".testfile")[0]         #=> "This is line one\n"
See also .lchown .lstat .lchmod .lutime also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0