← 返回命令列表

Linux command

readlink 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Print the target of a symbolic link

readlink [symlink]

Get the absolute path

readlink -f [path]

Get the absolute path

readlink -e [path]

Get the canonical path

readlink -m [path]

Print each resolved path on a new line

readlink -f [path1] [path2]

说明

readlink prints the value of a symbolic link or the canonical path of a file. Without options, it displays the immediate target of a symlink (one level only). The canonicalize options (-f, -e, -m) resolve the complete path by following all symbolic links, resolving references to /./ and /../, and returning an absolute pathname. The difference is how they handle non-existent components: - -f: All components except the last must exist - -e: All components must exist (strictest) - -m: No existence requirements (most permissive) This is commonly used in scripts to find the real location of files or to get absolute paths from relative ones.

参数

-f, --canonicalize
Canonicalize by following every symlink recursively; all components must exist
-e, --canonicalize-existing
Canonicalize, but all components must exist
-m, --canonicalize-missing
Canonicalize without requiring components to exist
-n, --no-newline
Do not output trailing newline
-q, --quiet
Suppress error messages
-s, --silent
Suppress error messages (same as -q)
-v, --verbose
Report error messages
-z, --zero
End each output line with NUL, not newline
--help
Display help and exit
--version
Output version information and exit

FAQ

What is the readlink command used for?

readlink prints the value of a symbolic link or the canonical path of a file. Without options, it displays the immediate target of a symlink (one level only). The canonicalize options (-f, -e, -m) resolve the complete path by following all symbolic links, resolving references to /./ and /../, and returning an absolute pathname. The difference is how they handle non-existent components: - -f: All components except the last must exist - -e: All components must exist (strictest) - -m: No existence requirements (most permissive) This is commonly used in scripts to find the real location of files or to get absolute paths from relative ones.

How do I run a basic readlink example?

Run `readlink [symlink]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -f, --canonicalize do in readlink?

Canonicalize by following every symlink recursively; all components must exist