Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method

File.link

(::path old_name, ::path new_name) -> 0
File.link(path, new_path) → 0

Not available on some systems.

Creates a new entry at new_path for the existing entry at path using a hard link:

Example
File.write('doc/t.tmp', 'foo')
File.link('doc/t.tmp', 'lib/u.tmp')
File.read('lib/u.tmp') # => "foo"
File.write('lib/u.tmp', 'bar')
File.read('doc/t.tmp') # => "bar"
File.delete('doc/t.tmp')
File.read('lib/u.tmp') # => "bar"
File.delete('lib/u.tmp')

Raises an exception if the entry at new_path exists.

See also .lchown .lstat .lchmod .lutime also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0