VMware ESXi and vSphere Cluster Management
Linux type Command: Identify Aliases, Builtins, and Executables
Learn how the Linux shell type command resolves aliases, functions, builtins, keywords, and PATH executables, with practical troubleshooting examples.
The shell command type reveals how the current shell would interpret a command name. It does more than locate a file: it reports whether the name refers to an alias, function, builtin, reserved word, or external executable.
This makes type a useful first diagnostic when a familiar command behaves unexpectedly. For example, an alias may add options, a function may replace an installed program, or an earlier directory in PATH may contain a different executable version.
What command resolution means
Command resolution is the shell's process of deciding what a command name refers to when you type it. The result might be shell-level behavior or a separate program file.
- An alias is a shell-defined text replacement, often used to attach default options.
- A shell function is a named, reusable block of shell code.
- A shell builtin is implemented inside the shell process rather than in a separate executable file.
- A reserved word is a shell-language keyword used as syntax, such as
if,for, orcase, where the shell supports reporting it. - An external command is an executable file launched from the filesystem, usually found through
PATH.
PATH is an ordered list of directories. When the shell searches for an external command, it normally checks those directories in order. Command shadowing occurs when a higher-priority definition or an earlier PATH entry hides another command with the same name.
Basic syntax
type [options] command_name ...
For example:
type pwd
type ls grep cat
You can provide several command names in one invocation. Each name is evaluated in the context of the active shell session, including that shell's aliases, functions, builtins, startup configuration, environment variables, and lookup state.
type is commonly a shell builtin, not a standalone portable utility. Consequently, its exact output, flags, and classification wording can differ between Bash, Zsh, and other shells.
Command classifications and output
| Category | What it means | Typical output pattern | Common source | Why it matters |
|---|---|---|---|---|
| Alias | A shell-level text replacement for the name. | ls is aliased to 'ls --color=auto' | Interactive startup files or user configuration. | Extra arguments may be added before the command runs. |
| Function | A named block of shell code. | grep is a function | A profile script or shell framework. | The function can override an external program. |
| Shell builtin | Functionality implemented by the shell itself. | pwd is a shell builtin | The shell implementation. | No separate executable needs to be selected. |
| Reserved word | A keyword used by the shell's grammar. | Wording such as if is a shell keyword | Shell language syntax. | The name has syntactic meaning, not ordinary executable lookup. |
| External executable | An executable file selected from a directory in PATH. | grep is /usr/bin/grep | An installed package or user-provided program. | The pathname and PATH order determine which file runs. |
| Not found | No applicable definition or executable was found. | type: command_name: not found | A misspelling, missing installation, or incomplete PATH. | The command cannot be resolved in the current session. |
Output wording is shell-specific. Treat phrases such as “is a shell builtin” and “is aliased to” as explanations for humans, not as a format guaranteed across all shells.
Checking common commands
Inspect a builtin with pwd
type pwd
In Bash and many other shells, the result identifies pwd as a shell builtin. Some systems also provide an external pwd executable, but the shell can use its builtin implementation first.
Inspect a possible ls alias
type ls
alias ls
A distribution or user configuration may define something like alias ls='ls --color=auto'. If no alias exists, type ls may instead report a function or an executable pathname. Never assume the alias exists on every system.
Inspect likely external programs
type grep
type cat
grep and cat are commonly external programs, so output often includes a path such as /usr/bin/grep. The actual result depends on the active shell, aliases, functions, installed software, and PATH.
Check an absent command
type command_that_does_not_exist
The first command normally prints a not-found message and returns a nonzero status. The second command displays the status of the immediately preceding command. Exact diagnostics vary by shell.
Find every applicable interpretation with -a
type -a ls
type -a grep
The -a option asks the shell to list all matching definitions and executable locations instead of only its primary interpretation. This is especially useful when an alias, function, builtin, and one or more PATH executables share a name.
For example, the output for type -a ls might include an alias followed by executable paths. The first result explains what an ordinary ls command uses; later results expose candidates that are being shadowed.
grep() { command grep --color=auto "$@"; }
type grep
type -a grep
unset -f grep
This temporary Bash-style function demonstrates shadowing. The function is selected before the external grep. command grep bypasses functions and aliases for that invocation, allowing the function to call the underlying command. unset -f grep removes the demonstration function.
General lookup precedence
The broad resolution model is:
- Check applicable aliases.
- Check shell functions.
- Handle shell builtins or reserved words.
- Search executable directories in
PATH.
Details vary by shell and by command context. Reserved words are part of shell syntax, and parsing rules can affect when a name is treated as a keyword. The practical lesson is that an expected executable may not run because a higher-priority alias, function, builtin, or earlier PATH entry has the same name.
| Lookup layer | Can override lower layers | Typical diagnostic command | Example problem |
|---|---|---|---|
| Alias | Usually yes for ordinary interactive command entry. | type COMMAND and alias COMMAND | ls silently receives extra display options. |
| Function | Yes, where the shell resolves functions before external commands. | type -a COMMAND | A wrapper changes arguments or environment variables. |
| Builtin or keyword | Shell-dependent, but normally selected instead of a same-named external file. | type COMMAND | cd must alter the current shell, so it is a builtin. |
Executable found in PATH | Earlier directories override later directories. | type -a COMMAND and printf '%s\n' "$PATH" | An older or unintended program version runs. |
Useful options and shell support
| Option | Purpose | Example | Shell support notes |
|---|---|---|---|
-a | List all applicable definitions and executable matches. | type -a python | Commonly supported, but verify the current shell. |
-t | Print a short category such as alias, function, builtin, file, or keyword. | type -t ls | Common in Bash; support and labels vary. |
-p | In Bash-compatible contexts, return an executable pathname while bypassing alias and function resolution. | type -p grep | Option behavior is shell-specific; consult builtin documentation. |
Use the active shell's help or manual to verify support:
help type # Bash
man bash # Bash reference
man zshbuiltins # Common Zsh reference
Do not assume that a flag accepted by Bash will have the same meaning in Zsh, Dash, Ksh, or another shell.
Comparing related lookup tools
| Tool | Detects aliases and functions | Detects builtins | Searches PATH | Best use case | Portability cautions |
|---|---|---|---|---|---|
type | Yes, in the current shell. | Yes, in the current shell. | Yes, for external matches. | Interactive diagnosis of shell interpretation. | It is commonly a shell builtin; output and options vary. |
command -v | Often, according to shell conventions. | Often. | Yes. | Checking whether a command is available in shell scripts. | Output conventions differ; test with the target shell. |
which | Often no, or only through shell-specific implementations. | Usually no. | Generally yes. | Finding a PATH executable on systems that provide it. | Implementation varies and it can miss aliases, functions, and builtins. |
whereis | No. | No. | Not as a report of shell resolution. | Searching conventional locations for binaries, source files, and manual pages. | It answers a filesystem-location question, not a shell-interpretation question. |
For interactive troubleshooting, type is generally the clearest choice because it asks the current shell what it would use. For scripts, command -v is commonly preferred for availability checks, but portable scripts should still account for shell differences.
Configuration and environment effects
Aliases and functions
Interactive aliases often come from files such as ~/.bashrc or ~/.zshrc, distribution defaults, or shell frameworks. Functions may be loaded from profile scripts or framework configuration.
alias NAME='replacement command'
unalias NAME
unset -f NAME
These commands affect the current shell session. Editing a startup file affects future sessions, or can be loaded into the current Bash interactive shell with:
source ~/.bashrc
Use the configuration file appropriate to the shell you actually run.
PATH ordering
printf '%s\n' "$PATH"
type -a COMMAND
When multiple external files have the same name, the first matching directory in PATH normally wins. type -a exposes the alternatives, while printing PATH helps explain their order.
Command hashing
Command hashing is shell caching of executable lookup locations. It avoids repeatedly searching PATH, but a cached location can matter after an executable is installed, removed, or moved.
hash -r
In Bash, hash -r refreshes cached command locations. Other shells provide different mechanisms, and some do not cache in the same way.
Practical troubleshooting
Unexpected default options
type COMMAND
type -a COMMAND
alias COMMAND
If an alias is responsible, use command COMMAND for a one-time bypass when appropriate, or remove it with unalias COMMAND. Also update the startup file that defines it if the change should persist.
A function runs instead of the installed utility
type COMMAND
type -a COMMAND
declare -f COMMAND
declare -f is useful in Bash-compatible shells for displaying a function definition. Use command COMMAND to bypass the function for one invocation, or use unset -f COMMAND and correct the configuration that loaded it.
The wrong executable version runs
type -a COMMAND
printf '%s\n' "$PATH"
First check for an alias or function. If the matches are all files, inspect PATH ordering and adjust it deliberately. Use an absolute path when a specific version is required, then run hash -r in Bash if cached lookup may be stale.
An installed command is unavailable
Check that the installation directory is in PATH, that the file has execute permission, and that its actual filename matches the command you entered. Open a new shell or refresh cached lookup results after correcting the environment.
An alias exists interactively but not in a script
Interactive shells and noninteractive shells commonly load different startup files. In Bash, aliases usually do not expand in scripts unless alias expansion is explicitly enabled. Automation should not depend on interactive aliases; use explicit options, functions loaded intentionally, or fully specified commands instead.
Results differ between machines
echo "$SHELL"
bash -ic 'type ls'
zsh -ic 'type ls'
Identify the shell and version, then consult its builtin documentation. Startup files, shell frameworks, user configuration, PATH, and installed programs can all change the result.
Safe interpretation and scripting limits
type reports the current shell's behavior for the current user, session, and environment. It does not provide a universal answer for every user, shell, script, or future session.
- An alias shown in an interactive terminal may not exist in a noninteractive shell.
- Shell functions can be defined only in the current shell or in configuration loaded by that shell.
PATHand shell hashing can change which executable is selected.- Output formats differ, so scripts should not blindly parse human-readable
typeoutput. - For shell scripts, use the intended interpreter and prefer carefully tested shell-native checks such as
command -vwhen appropriate.
Exam-relevant notes
typeanswers “What will this shell use for this name?” rather than simply “Where is a file with this name?”type -ais the key option for discovering shadowing and all matching definitions.whichis generally PATH-focused and can miss aliases, functions, and builtins.command -vis commonly useful in scripts, but its output remains shell-dependent.whereissearches conventional filesystem locations for binaries, source, and manual files; it does not report shell resolution.- Aliases and functions are shell-session features, while external commands are files selected through the environment and filesystem.
Quick reference
| Goal | Command |
|---|---|
| Show the primary interpretation | type COMMAND |
| Show every definition and executable match | type -a COMMAND |
| Show a concise type where supported | type -t COMMAND |
| Find an executable path in Bash-compatible contexts | type -p COMMAND |
| Inspect the current aliases | alias |
| Remove an alias | unalias COMMAND |
| Remove a function | unset -f COMMAND |
| Inspect the executable search path | printf '%s\n' "$PATH" |
| Refresh Bash command hashing | hash -r |
When command behavior is surprising, begin with type COMMAND, follow with type -a COMMAND, and then inspect aliases, functions, PATH, and shell configuration. This sequence usually reveals which interpretation is taking precedence.
See the Linux type command reference for the core syntax and diagnostic workflow.