#Bash 的 readlink 命令
readlink [OPTION]... FILE...
功能
获取符号链接的源文件路径。
类型
可执行文件(/usr/bin/readlink),属于 coreutils。
参数
OPTION选项:-f,--canonicalize- 将路径规范化为绝对路径(realpath),路径的所有组成部分(除了最后一部分)都必须存在-e,--canonicalize-existing- 将路径规范化为绝对路径,路径的所有组成部分都必须存在-m,--canonicalize-missing- 将路径规范化为绝对路径,路径的所有组成部分都可以不存在-n,--no-newline- 不要输出尾随的分隔符-q,--quiet- 不打印错误信息-s,--silent- 不打印错误信息;默认-v,--verbose- 打印错误信息-z,--zero- 以空字符(\0)作为行的结尾,而不是换行符(\n)--help- 显示帮助--version- 显示版本
FILE- 文件列表,如果没有这个参数或指定为-,则读取标准输入
#示例
$ touch 1.txt # 创建普通文件
$ readlink 1.txt # 查看普通文件 没有任何输出
$ readlink -v 1.txt # 开启错误信息
readlink: 1.txt: Invalid argument
$ ln -s 1.txt 2.txt # 创建软链接
$ readlink 2.txt # 查看软链接
1.txt
$ readlink -f 2.txt # 规范化为绝对路径
/home/primers/1.txt
#相关命令
| 命令 | 说明 |
|---|---|
| ln | 创建文件的链接(硬链接或符号链接) |
#推荐阅读
#手册
READLINK(1) User Commands READLINK(1)
NAME
readlink - print resolved symbolic links or canonical file names
SYNOPSIS
readlink [OPTION]... FILE...
DESCRIPTION
Note realpath(1) is the preferred command to use for canonicalization
functionality.
Print value of a symbolic link or canonical file name
-f, --canonicalize
canonicalize by following every symlink in every component of
the given name recursively; all but the last component must ex‐
ist
-e, --canonicalize-existing
canonicalize by following every symlink in every component of
the given name recursively, all components must exist
-m, --canonicalize-missing
canonicalize by following every symlink in every component of
the given name recursively, without requirements on components
existence
-n, --no-newline
do not output the trailing delimiter
-q, --quiet
-s, --silent
suppress most error messages (on by default)
-v, --verbose
report error messages
-z, --zero
end each output line with NUL, not newline
--help display this help and exit
--version
output version information and exit
AUTHOR
Written by Dmitry V. Levin.
REPORTING BUGS
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report any translation bugs to <https://translationproject.org/team/>
COPYRIGHT
Copyright © 2023 Free Software Foundation, Inc. License GPLv3+: GNU
GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
readlink(2), realpath(1), realpath(3)
Full documentation <https://www.gnu.org/software/coreutils/readlink>
or available locally via: info '(coreutils) readlink invocation'
GNU coreutils 9.4 April 2024 READLINK(1)