Explaining Shell Commands in the Shell

Use the explain API to explain commands - from the command line!

Jackson Pauls By Jackson Pauls
[j@lianli ~]$ explain 'tar -xf tarball.tar.gz'

tar(1)
  GNU `tar' saves many files together into a single tape or disk archive, and
  can restore individual files from the archive. [...]

  -x (-x, --extract, --get)
    extract files from an archive

  -f tarball.tar.gz (-f, --file=ARCHIVE)
    use archive file or device ARCHIVE

[j@lianli ~]$

Neat?

(Update: there's now also an npm module.)

Here's the bash function behind this:

This uses an API to get text output from our recently introduced explain functionality.
Give it a quick spin:

curl -Gs "https://www.mankier.com/api/explain/" --data-urlencode "q=tar -xf tarball.tar.gz"

Interactive mode looks like this (user input in bold):


[j@lianli ~]$ explain
Command: ls -l

ls(1)
  List information about the FILEs (the current directory by default). Sort
  entries alphabetically if none of -cftuvSUX nor --sort is specified.
  Mandatory arguments to long options are mandatory for short options too.

  -l (-L)
    use a long listing format
                                                   https://mankier.com/1/ls

Command: du -s * | sort -n | tail

du(1)
  Summarize disk usage of the set of FILEs, recursively for directories.
  Mandatory arguments to long options are mandatory for short options too.

  -s (-S, --SUMMARIZE)
    display only a total for each argument

  *
                                                   https://mankier.com/1/du

---------------------------------------------------------------------pipe--

sort(1)
  Write sorted concatenation of all FILE(s) to standard output. With no
  FILE, or when FILE is -, read standard input. Mandatory arguments to long
  options are mandatory for short options too.

  -n (-N, --NUMERIC-SORT)
    compare according to string numerical value
                                                 https://mankier.com/1/sort

---------------------------------------------------------------------pipe--

tail(1)
  Print the last 10 lines of each FILE to standard output. With more than
  one FILE, precede each with a header giving the file name. With no FILE,
  or when FILE is -, read standard input. Mandatory arguments to long
  options are mandatory for short options too.
                                                 https://mankier.com/1/tail

Command: [ctrl+d] Bye!