Skip to content

Linux readlink command

The Linux readlink command is used to print out the target of a symbolic link. By running this command, you can quickly determine the path that a symbolic link is pointing to. This can be especially useful when you need to troubleshoot or understand the structure of your file system. The readlink command can also be used with options to manipulate the output format and display additional information. Overall, mastering the readlink command can help improve your efficiency and productivity when working with symbolic links in Linux environments.

Terminal window
readlink [option] [file]

Options:

OptionDescription
-f, —canonicalizeCanonicalize the given filename by following every symlink in every component of the given name recursively

Parameters:

ParameterDescription
fileThe name of the file whose link target will be printed
Terminal window
readlink -f mylink

This command will display the absolute path of the symbolic link named “mylink”.

Terminal window
readlink mylink

This command will show the target file or directory of the symbolic link named “mylink”.

Terminal window
readlink -e mylink

By using the -e option, this command resolves multiple levels of symbolic links starting from the given symbolic link named “mylink”.

Display the Canonicalized Path of a File

Terminal window
readlink -m mylink

When using the -m option, this command will display the canonicalized path of the file or directory named “mylink”, which resolves any symbolic links in the path.

To use the readlink command in Linux, execute the following command:

Terminal window
readlink /path/to/symlink

The readlink command in Linux is used to print the resolved symbolic links or canonical file names.

To display the canonicalized path of a file with readlink in Linux, use the following command:

Terminal window
readlink -f /path/to/file

To show all links in a symbolic link chain with readlink in Linux, you can use the -e option like this:

Terminal window
readlink -e /path/to/symlink

To suppress error messages when using readlink in Linux, you can use the -q or --quiet option like this:

Terminal window
readlink -q /path/to/symlink

To only display the target if the link points to a directory with readlink in Linux, you can use the -m or --canonicalize-missing option like this:

Terminal window
readlink -m /path/to/symlink

To have readlink follow all symbolic links and print the final target in Linux, you can use the -e or --canonicalize option like this:

Terminal window
readlink -e /path/to/symlink
  • Resolve symbolic links
  • Print the resolved path of a symbolic link
  • Display the final target of a symbolic link