How do I get the target of a symlink?

Solution 1:

I think readlink is what you are looking for:

File.readlink("path/to/symlink")

Solution 2:

require 'pathname'
Pathname.new("symlink").realpath

or readlink as others said

Solution 3:

Or you can try:

File.realpath("symlink_path")

Which works for both symlinks and normal files.