Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. 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.2 · 3.1 · 3.0