2

I'll mention this first - the goal of this question is really to bolster my understanding of bash and the info bash pages rather than to get specific answers on the functionality of the date command.

I'm unable to find any mention of the date command from the following indices of the info bash manual:

  • Builtin Index:: Index of Bash builtin commands.
  • Reserved Word Index:: Index of Bash reserved words.
  • Variable Index:: Quick reference helps you find the variable you want.
  • Function Index:: Index of bindable Readline functions.

However, I'm able to get information on the date function with info date. This page seems to a part of the BSD General Commands Manual but I'm unable to find the index page of this manual - if I go to the containing node though typing 'u' this takes me to the 'dir' page rather than an general command index as I would expect.

My main concern here is that if I can't find information on the date command within info bash, then what other commands aren't listed within info bash? Is there a comprehensive list of all of the commands I can use within Bash?

mklement0
  • 382,024
  • 64
  • 607
  • 775
BenWS
  • 521
  • 2
  • 6
  • 20

1 Answers1

2

info bash and man bash only document Bash's own features.

External utilities such as date have nothing to with Bash per se, even though you can call them from Bash.

  • For any given external utility you'll find documentation in its specific man and info pages (if installed), as you've discovered.

  • What muddles the issue is that Bash has so-called builtins that look and behave like external utilities in many respects - those have specific help topics that you can invoke with help; e.g., help read, but you can also find them in man bash under the heading SHELL BUILTIN COMMANDS.
    Furthermore, some command names, e.g. echo, exist both as Bash builtins and as external utilities (/bin/echo).

While just info (without arguments) will show you a list of external utilities, typically under heading Individual utilities, there are problems; depending on your system:

  • The list may be incomplete, or spread across multiple locations.

  • The documentation may not refer to the actual utilities installed on your system.

    • For instance, on OSX the info topics document the GNU core utilities, whereas OSX mostly comes with BSD utilities.
  • If, however, your system is a Linux distro that does use the GNU utilities (which is the norm) and the info command is the one that came with bash, you may be fine.

  • See below for commands that allow you to find all external utilities in your $PATH.

  • An alternative way to get a list of external utilities is to consult the set of POSIX-mandated utilities; note that this list will only be a subset of the set of utilities installed on most modern platforms; similarly, the individual utility description will typically only describe the - standardized - subset of a given platform's version of that utility, because most utilities implement nonstandard extension:

    • Go to Shell & Utilities: Detailed Toc and search for heading Utilities (as the full heading), which lists all external utilities a POSIX-compliant system must have.I couldn't find a direct link to a page listing all utilities by name.
    • POSIX also mandates the builtins (built-in utilities) that a POSIX-compliant shell must implement (of which the Bash builtins are a superset):

Additional information:

  • To see whether a given command is a builtin, use, e.g.:
 $ type read
 read is a shell builtin
  • To see all forms of a command, use option -a, e.g.:
 $ type -a read
 read is a shell builtin
 read is /usr/bin/read

How to find all (external) utilities in your $PATH:

  • The following command will output a list of all executables in your $PATH (this can be a long list); also note that the list will typically include utilities that were custom-installed; the list will contain full paths, grouped by directory:

    • The command looks for files that are executable by the o (other, rest of the word) security principal, which all preinstalled utilities should be; conceivably, there are additional utilities that have the permissions attribute only for the u and/or g principal.
printf '%s' "$PATH" | tr ':' '\n' | xargs -I {} find {} -maxdepth 1 -type f -perm -o=x
  • If you want a sorted list of mere executable names, use:
printf '%s' "$PATH" | tr ':' '\n' | xargs -I {} find {} -maxdepth 1 -type f -perm -o=x |
  awk -F/ '{ print $NF }' | sort -u
  • The above lists only unique names; it is possible for distinct duplicates of executables with the same filename to exist in multiple directories in the $PATH (in which case the one whose directory comes first in $PATH "wins"); to see a list of duplicates, prefixed with their occurrence count, use:
printf '%s' "$PATH" | tr ':' '\n' | xargs -I {} find {} -maxdepth 1 -type f -perm -o=x |
  awk -F/ '{ print $NF }' | sort | uniq -c | grep -v ' *1'
  • For any given name with duplicates you can use which -a <name> to see the full paths of all duplicates.

Finally, tab completion can be helpful in discovering commands:

  • Type man and press the Tab key repeatedly to list / cycle through all command; specify a command prefix - e.g., man dat - to only list / cycle through the commands that start with that prefix (the exact behavior depends on your readline configuration).

    • By default this does not work with info (at least on the OSX and Ubuntu systems that I've tried this on from Bash).
  • This also works when starting to type a command name to invoke.

    • However, that requires typing at least one letter, which limits the matches to commands whose name starts with that letter.
    • To discover all executables in a given folder, use:
      • ./<tab> in the current folder.
      • /usr/bin/<tab>, for instance, in a specific folder.
mklement0
  • 382,024
  • 64
  • 607
  • 775
  • This is great! Thank you for all of the details...at first glance this answer definitely provides the information I was looking for. – BenWS Feb 28 '16 at 17:37
  • @BenWS: My pleasure; turns out that just `info` (no arguments) may give you what you want, but there are caveats - see my updated (and restructured) answer. – mklement0 Feb 28 '16 at 19:02