2

我将首先提到这一点 - 这个问题的目的实际上是加强我对 bash 和info bash页面的理解,而不是获得有关 date 命令功能的具体答案。

我无法从手册的以下索引中找到该命令的任何提及:dateinfo bash

  • 内置索引:: Bash 内置命令的索引。
  • Reserved Word Index:: Bash 保留字的索引。
  • 变量索引::快速参考可帮助您找到所需的变量。
  • Function Index:: 可绑定 Readline 函数的索引。

但是,我可以使用info date. 此页面似乎是 BSD 通用命令手册的一部分,但我无法找到本手册的索引页面 - 如果我通过键入“u”进入包含节点,这会将我带到“dir”页面而不是正如我所期望的一般命令索引。

我在这里主要担心的是,如果我无法在其中找到有关date命令的信息info bash,那么还有哪些其他命令未在其中列出info bash?是否有我可以在 Bash 中使用的所有命令的完整列表?

4

1 回答 1

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.
于 2016-02-28T17:30:21.237 回答