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 -fThis 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 -eThis option will canonicalize by following every symlink in every component of the given name recursively, all components must exist.
Example:
readlink -e deskThis 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 -nThis 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 -qThis option will execute in quiet mode.
Example:
readlink -q deskWith 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 desk57. 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 -zThis 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 --helpThis option will display this help and exit.
Example:
readlink --help10. readlink --version
This option will show the version information and exit.
Example:
readlink --version
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4