command is a Unix shell command for looking up commands. The command is available on Unix and Unix-like operating systems. It is specified in the POSIX standard and is often implemented in Unix shells as a shell builtin function or alias.
Usage command has two main modes: execution and inspection, depending on the optional flags that are specified as its first command-line arguments.
Execution By default, command takes the name of a command, followed by zero or more arguments for it. It then follows a special procedure to look up the command name, and runs it with the given arguments. This procedure makes the following modifications to normal command execution:
It bypasses shell functions, aliases, and reserved words, which would normally take precedence. Even if it runs a "special built-in utility", it handles errors and variable assignments like it would for a normal command. In this mode, it can have the following exit statuses:
The status produced by the target command, if it was run. 126 if the command was found but could not be run. 127 if there is no command by the given name, or command had some other error condition.
Inspection When the -v flag or the -V flag is specified, command takes just the name of a command, and outputs information about it. The -v flag causes command to expand the given name, outputting what it refers to: (followed by a newline character)
The absolute path of an executable The definition of an alias The name of a shell function or built-in Nothing if the lookup fails The -V flag causes command to output a human-readable description of what the name refers to, specifying whether it is an executable (including its absolute path), function, alias (including its definition), special or regular built-in, or shell reserved word. In this mode, the exit status is 0 on success and positive on error.
Mode-independent flags command has one mode-independent flag, -p. This causes it to override the PATH environment variable and instead use a default value on which all of the standard utilities are located.
Examples In the following, the ls command is run directly instead of invoking a function or alias with the same name.
See also List of POSIX commands
Main sources command – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Group The documentation for command(1p) is also available at websites such as manned.org and man7.org.
Additional references