Linux常用命令详解 | readlink

readlink是Linux系统中一个常用工具,主要用来找出符号链接所指向的位置。

$readlink --help
Usage: readlink [OPTION]... FILE...
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 exist
  -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
  -v, --verbose                 report error messages
  -z, --zero                    separate output with NUL rather than newline
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: 
Report readlink translation bugs to 
For complete documentation, run: info coreutils 'readlink invocation'

举例:系统中的awk命令到底是执行哪个可执行文件呢?

$ readlink /usr/bin/awk  
/etc/alternatives/awk  ----> 其实这个还是一个符号连接  


$ readlink /etc/alternatives/awk  
/usr/bin/gawk  ----> 这个才是真正的可执行文件  

-f: 可以递归跟随给出文件名的所有符号链接以标准化,除最后一个外所有组件必须存在。简单地说,就是一直跟随符号链接,直到非符号链接的文件位置,限制是最后必须存在一个非符号链接的文件。

$ readlink -f /usr/bin/awk  
/usr/bin/gawk

ref: https://blog.csdn.net/youmatterhsp/article/details/80375260

你可能感兴趣的:(Linux常用命令详解 | readlink)