How to find all the available tools in mac terminal?

Solution 1:

The easiest is simply to open the Terminal and then press the TAB key twice. You'll be asked if you want to see all possibilities - reply "y" and you'll get the full list.

Solution 2:

See the answers from this U&L Q&A titled: List all commands that a shell knows .

My personal favorite is to utilize compgen since this is part of the family of tools used to build all the tab completion when you're in a terminal and hit tab> + tab twice.

$ compgen -c

Example

$ compgen -c | tail
deepcopy-gen
kube-controller-manager
informer-gen
lister-gen
etcd
gen-apidocs
kube-apiserver
kubectl
kubebuilder
conversion-gen

Incidentally, if you want to know where one of these executables lives on your HDD use type -a <cmd> to find it:

$ type -a ansible
ansible is aliased to `ANSIBLE_CONFIG=~/.ansible.cfg ansible'
ansible is /usr/local/bin/ansible

This shows that the command ansible is an alias and also lives locally on the HDD here: /usr/local/bin/ansible.

References

  • 8.7 Programmable Completion Builtins

Solution 3:

You could take the PATH variable and translate the colons into spaces then list the files in those directories.

ls  $(tr ':' ' ' <<<"$PATH")

And as Peter Cordes points out, the above will break if directory paths have spaces in their name. In a subshell, change the IFS (Internal Field Separator) to only a newline and translate the colons to newlines.

( IFS=$'\n'; ls  $(tr ':' '\n' <<<"$PATH") )  

Solution 4:

When a command is installed, an entry should have been placed in the whatis database. However, there is no requirement to do so. To get a one line description of a command in the database, enter whatis followed by the command. For example, the output from entering whatis "ruby" is shown below.

erb(1)                   - Ruby Templating
irb(1)                   - Interactive Ruby Shell
ri(1)                    - Ruby API reference front end
ruby(1)                  - Interpreted object-oriented scripting language

This the whatis command will accept regular expressions. Therefore, to get a list of all commands in the database, enter the command given below.

whatis "."

The man page for whatis states the following:

whatis searches a set of database files containing short descriptions of system commands for keywords and displays the result on the standard output. Only complete word matches are displayed.

There also exists a similar command called apropos. The man page for apropos states the following:

apropos searches a set of database files containing short descriptions of system commands for keywords and displays the result on the standard output.

Basically, the difference is apropos does not require complete word matches. For example, whatis "string" would not find a match when encountering strings, but apropos "string" would.