Linux command
type 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Show the type
type [command]
Show all locations
type -a [command]
Show only the type
type -t [command]
Show the path
type -P [command]
Check if command is
type -t [cd]
Show path only
type -p [command]
Suppress function lookup
type -f [command]
说明
type is a shell builtin that displays how a command name would be interpreted. It identifies whether a name is an alias, shell keyword, function, builtin command, or external executable file. Without options, type prints a descriptive message showing the command type and location. With -t, it outputs just the type category as a single word, useful for scripting. The -a option shows all interpretations of a name, revealing if multiple commands exist with the same name (e.g., an alias shadowing an executable). The -P option forces a PATH search, useful for finding the executable even when an alias or function exists. type is more informative than which because it understands shell internals like aliases, functions, and builtins, not just files in PATH.
参数
- -a
- Display all locations containing an executable; includes aliases, builtins, and functions
- -f
- Suppress shell function lookup
- -p
- Return disk file path only if type would return "file"; empty otherwise
- -P
- Force PATH search even for aliases, builtins, or functions
- -t
- Output single word: alias, keyword, function, builtin, file, or empty
FAQ
What is the type command used for?
type is a shell builtin that displays how a command name would be interpreted. It identifies whether a name is an alias, shell keyword, function, builtin command, or external executable file. Without options, type prints a descriptive message showing the command type and location. With -t, it outputs just the type category as a single word, useful for scripting. The -a option shows all interpretations of a name, revealing if multiple commands exist with the same name (e.g., an alias shadowing an executable). The -P option forces a PATH search, useful for finding the executable even when an alias or function exists. type is more informative than which because it understands shell internals like aliases, functions, and builtins, not just files in PATH.
How do I run a basic type example?
Run `type [command]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -a do in type?
Display all locations containing an executable; includes aliases, builtins, and functions