Giter VIP home page Giter VIP logo

rreadlink's Introduction

npm version license

Contents

rreadlink — introduction

rreadlink is a multi-platform Unix CLI that prints a symlink's complete chain of targets using absolute paths; it can also determine the canonical path of non-symlinks.

The primary purpose of rreadlink (recursive readlink) is to follow a given symlink to its ultimate target, printing all intermediate symlinks along the way.
All paths are printed as absolute paths, with the ultimate target printed in canonical form.

This is hepful on Linux platforms, for instance, where some utilities are installed as symlinks that point to other symlinks before resolving to the ultimate target, making it difficult to understand what is ultimately invoked;
e.g., on some Linux distros /usr/bin/nawk links to /etc/alternatives/nawk, which in turn links to the actual target, /usr/bin/gawk.
Note that the native GNU readlink utility can either only give you the next target (not the ultimate one), or, with -f or -e or -m, only the ultimate target (not intermediate ones).

Loosely speaking, rreadlink provides the functionality of GNU readlink -e while also including intermediate targets. rreadlink has the added advantage of being multi-platform (see Installation below).

Alternatively, given a non-symlink, rreadlink prints the argument's canonical path (i.e., any directory components that are symlinks are resolved to their ultimate targets).

Find examples below, concise usage information further below, or read the manual.

See also: The typex utility provides information about executables in the path (among other things) and has rreadlink's behavior built in to show what file is ultimately invoked.

Examples

# Print the symlink chain for executable /usr/bin/nawk (e.g., on Ubuntu):
$ rreadlink /usr/bin/nawk
/usr/bin/nawk@ -> /etc/alternatives/nawk@ -> /usr/bin/gawk

# Ditto, but printing one path per line, without the symlink sigil (@):
# (This format is the default when not outputting to a terminal.)
$ rreadlink -1 /usr/bin/nawk
/usr/bin/nawk
/etc/alternatives/nawk
/usr/bin/gawk

# Canonicalize the path of a non-symlink:
# (Assume that /var links to /private/var and that log is a regular file.)
$ rreadlink /var/log
/private/var/log

Installation

Supported platforms

Unix-like platforms with POSIX-compatible utilities and Bash, such as Linux and OS X.

Installation from the npm registry

Note: Even if you don't use Node.js, its package manager, npm, works across platforms and is easy to install; try curl -L http://git.io/n-install | bash

With Node.js or io.js installed, install the package as follows:

[sudo] npm install rreadlink -g

Note:

  • Whether you need sudo depends on how you installed Node.js / io.js and whether you've changed permissions later; if you get an EACCES error, try again with sudo.
  • The -g ensures global installation and is needed to put rreadlink in your system's $PATH.

Manual installation

  • Download the CLI as rreadlink.
  • Make it executable with chmod +x rreadlink.
  • Move it or symlink it to a folder in your $PATH, such as /usr/local/bin (OSX) or /usr/bin (Linux).

Usage

Find concise usage information below; for complete documentation, read the manual online or, once installed, run rreadlink nws (rreadlink --man if installed manually).

$ rreadlink --help


Recursively resolves symlinks by printing the chain of targets using absolute  
paths or prints the canonical path of a symlink's ultimate target or of a  
non-symlink.

    rreadlink [-s|-1] symLink
    rreadlink -e symLink

    -s     single-line output format using ' -> ' between paths and
           @ to mark symlinks (default when printing to terminal)
    -1     one-line-per-path output format, without the @ marker (default
           when NOT printing to a terminal)
    -e     print only the symlink's ultimate target, in canonical form

Standard options: --help, --man, --version, --home

License

Copyright (c) 2015 Michael Klement [email protected] (http://same2u.net), released under the MIT license.

Acknowledgements

This project gratefully depends on the following open-source components, according to the terms of their respective licenses.

npm dependencies below have optional suffixes denoting the type of dependency; the absence of a suffix denotes a required run-time dependency: (D) denotes a development-time-only dependency, (O) an optional dependency, and (P) a peer dependency.

npm dependencies

Changelog

Versioning complies with semantic versioning (semver).

  • v0.2.1 (2015-10-21):

    • [dev] Improved robustness of interal rreadlinkchain() function.
  • v0.2.0 (2015-09-18):

    • [potentially breaking change] rreadlink now also accepts options placed after operands on the command line (except after --).
    • [doc] rreadlink now has a man page (if manually installed, use rreadlink --man); rreadlink -h now just prints concise usage information.
    • [doc] README.md cleaned up and extended.
    • [dev] Removed post-install command that verifies presence of Bash, because npm prints the command during installation, which can be confusing.
  • v0.1.6 (2015-09-15):

    • [dev] Makefile improvements; various other behind-the-scenes tweaks.
  • v0.1.5 (2015-06-26):

    • [doc] Read-me: npm badge changed to shields.io; license badge added; typo fixed.
    • [dev] To-do added; Makefile updated.
  • v0.1.4 (2015-05-30):

  • v0.1.3 (2015-02-11):

    • Doc: Read-me improvements.
  • v0.1.2 (2015-02-11):

    • Doc: Read-me and CLI help improvements.
  • v0.1.1 (2015-02-11):

    • Dev: Tests improved.
  • v0.1.0 (2015-02-11):

    • Initial release.

rreadlink's People

Contributors

mklement0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

tlevine

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.