Linux command
command 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Run a command ignoring shell functions
command [ls]
Check if a command exists
command -v [git] && echo "git is installed"
Get the path of a command
command -v [python3]
Describe a command's type
command -V [cd]
Run external command when function exists with same name
ls() { command ls --color=auto "$@"; }
说明
command is a shell builtin that executes a command, bypassing shell functions with the same name. This is essential when writing wrapper functions that need to call the original command they're wrapping. With -v, it prints how the command would be resolved: the path for external commands, the definition for aliases, or indication for builtins and functions. This is the POSIX-portable way to check if a command exists (preferred over which). The -V option provides verbose output describing what type of command it is (builtin, function, alias, or external) and where it's defined.
参数
- -v
- Print the pathname or alias that would be used (like which).
- -V
- Verbose description of command type.
- -p
- Use default PATH to find command, ignoring custom PATH.
FAQ
What is the command command used for?
command is a shell builtin that executes a command, bypassing shell functions with the same name. This is essential when writing wrapper functions that need to call the original command they're wrapping. With -v, it prints how the command would be resolved: the path for external commands, the definition for aliases, or indication for builtins and functions. This is the POSIX-portable way to check if a command exists (preferred over which). The -V option provides verbose output describing what type of command it is (builtin, function, alias, or external) and where it's defined.
How do I run a basic command example?
Run `command [ls]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -v do in command?
Print the pathname or alias that would be used (like which).