readlink command in Linux with Examples
Last Updated :
05 Sep, 2024
The ‘readlink’ command in Linux is a valuable tool used to print resolved symbolic links or canonical file names. In simpler terms, when dealing with symbolic links and you need to know the actual path they represent, the ‘readlink’ command reveals the path of the symbolic link. This command is particularly useful for system administrators, developers, and users who work with complex directory structures and need to trace symbolic links effectively.
What is the ‘readlink’ Command?
Symbolic links in Linux are pointers to another file or directory. The ‘readlink’ command helps you determine the exact path that these links point to. It’s an essential command for managing symbolic links and understanding their relationships within the file system.
Syntax:
readlink [OPTION]... FILE...
‘readlink’ command Example in Linux
It will print the print resolved symbolic links or canonical file names of the symbolic link passed with the command as shown below.

Explanation: As you can see in the above example we have a symbolic link with the name of the ‘desk’ with the help of ‘readlink’ command we will be able to identify its actual path.
Common Options with ‘readlink’ Command
1. readlink -f
This option canonicalize by following every symlink in every component of the given name recursively; all but the last component must exist.
Example:
readlink -f desk1

This command will display the resolved path by recursively following all symbolic links up to the final component, even if the final component does not exist.
2. readlink -e
This option will canonicalize by following every symlink in every component of the given name recursively, all components must exist.
Example:
readlink -e desk
This option is similar to ‘-f’ option the only difference between ‘-f’ and ‘-e’ option is in ‘-e’, all components must exist and in ‘-f’, the last component must exist.
3. readlink -m
This option canonicalize by following every symlink in every component of the given name recursively, without requirements on components existence.
Example:
readlink -m desk3

This option is useful when you want to resolve a path even if some of the components in the path do not exist.
4. readlink -n
This option will do not output the trailing delimiter.
Example:
readlink -n desk4

This can be useful when you need to combine the output of ‘readlink’ with other commands or scripts without additional line breaks.
5. readlink -q
This option will execute in quiet mode.
Example:
readlink -q desk
With the help of this option the user can read the symbolic links in every component and nothing like errors is being displayed on the console.
6. readlink -s
This option will suppress most error messages.
Example:
readlink -s desk5

7. readlink -v
This option will report error messages if any.
Example:
readlink -v desk6

This option is useful when troubleshooting symbolic links, as it provides a complete output with any error messages.
8. readlink -z
This option will end each output line with NUL, not newline.
Example:
readlink -z desk2

This is particularly useful when processing output in environments where newline characters might interfere with data processing.
9. readlink –help
This option will display this help and exit.
Example:
readlink --help

10. readlink –version
This option will show the version information and exit.
Example:
readlink --version

Similar Reads
How to Check Network Connectivity in Linux | ping Command
Ensuring a stable and reliable internet connection is crucial for seamless navigation and efficient communication in the world of Linux. The "ping" command is a powerful tool that allows users to check the status of their internet connection and diagnose network-related issues. In this article, we w
7 min read
Pinky command in Linux with Examples
Pinky command is a user information lookup command which gives details of all the users logged in. This tool is generally used by system administrators. It is similar to the finger tool but in many Linux, Systems pinky comes pre-installed while finger doesn't, so this command is useful in case you d
2 min read
pmap command in Linux with Examples
The pmap command in Linux is a powerful utility used to display the memory map of a process. A memory map provides insight into how memory is allocated and distributed within a running process. This can be incredibly useful for developers and system administrators when debugging memory issues, optim
4 min read
halt, poweroff and reboot Commands in Linux
In Linux systems, the halt, poweroff, and reboot commands are essential tools for controlling the system's hardware by stopping the CPU, shutting down the system, or restarting it. These commands are typically restricted to superusers, as they involve critical actions that impact the system hardware
4 min read
printf command in Linux with Examples
The 'printf' command in Linux is a versatile tool used to display formatted text, numbers, or other data types directly in the terminal. Like the 'printf' function in programming languages like C, the Linux printf command allows users to format output with great precision, making it ideal for script
4 min read
How to List Running Processes in Linux | ps Command
As we all know Linux is a multitasking and multi-user system. So, it allows multiple processes to operate simultaneously without interfering with each other. Process is one of the important fundamental concepts of the Linux OS. A process is an executing instance of a program that carries out differe
9 min read
How to Display Current Working Directory in Linux | pwd Command
The 'pwd,' which stands for "print working directory." In this article, we will delve into the 'pwd' command, exploring its functionality, usage, and various examples. It prints the path of the working directory, starting from the root. pwd is shell built-in command(pwd) or an actual binary(/bin/pwd
4 min read
ranlib command in Linux with Examples
ranlib command in Linux is used to generate index to archive. ranlib generates an index to the contents of an archive and it will be stored in the archive. The index lists each symbol defined by a member of an archive which is simply a relocatable object file. You may use 'nm -s' or 'nm âprint-armap
4 min read
rcp Command in Linux with examples
When working in a Linux environment, there often comes a time when you need to transfer files from one computer to another. While more secure options like scp or rsync exist, the rcp (Remote Copy Protocol) command offers a simple and efficient way to copy files between systems, especially for beginn
5 min read
read command in Linux with Examples
read command in the Linux system is used to read from a file descriptor. This command reads up the total number of bytes from the specified file descriptor into the buffer. If the number or count is zero, this command may detect errors. But on success, it returns the number of bytes read. Zero indic
3 min read