Linux online course

Linux type Command: Identify Aliases, Builtins, and Executables

Learn how to use the Linux shell type command to identify aliases, builtins, functions, keywords, and executable files selected for a command name.

When you type a command such as ls or pwd, the shell must decide what that name refers to. It might expand an alias, invoke a shell function, run a shell builtin, or search the PATH for an external executable.

The type command reports how the current shell interprets a command name. This makes it useful for learning, troubleshooting, writing scripts, and checking an administrator's environment.

What the type Command Does

A command name is the text you enter, such as grep. The implementation selected for that name is what the shell actually invokes. These are not always the same thing: typing ls might invoke an alias rather than the ls executable.

type displays the command resolution result: the shell's decision about what a name means in the current session. Depending on the shell and configuration, a name can resolve to an alias, shell function, shell builtin, reserved word or other shell keyword, or external executable.

A shell builtin is implemented directly inside the shell process. An external command is an executable file found by searching directories listed in PATH. An alias is shell text substitution, while a shell function is a named block of shell code that can be invoked like a command.

Basic Syntax

type [OPTION]... NAME...

NAME is one or more command names to inspect. You can check several names in one invocation:

type cd pwd ls

In Bash and many other shells, type is a shell builtin rather than a separate executable stored in a directory. This matters because the shell needs to inspect its own aliases, functions, builtins, and command lookup rules.

Reading type Output

Shell builtin

A typical Bash result for pwd is:

pwd is a shell builtin

This means the shell can run pwd internally without finding an external file first. The exact wording varies among shells.

Alias

If ls has been configured as an alias, output may look like this:

ls is aliased to `ls --color=auto'

The alias changes the command text before normal command execution. Your output may use a different option or quote style, or ls may not be aliased at all.

External executable

For an ordinary external utility, output commonly includes its full path:

grep is /usr/bin/grep

The path shown is the executable selected from the current PATH. Different systems may install the file in another directory.

Functions, keywords, and unavailable names

Shells can also report functions and reserved words. For example, a function result may resemble:

deploy is a function

A reserved word such as if may be identified as a shell keyword or reserved word. If no applicable interpretation exists, the shell usually reports a not-found result, such as:

example_command: not found

How type Classifies Command Names

Result categoryMeaningTypical output patternExample command name

Alias — A text substitution defined by the shell — ls is aliased to ...ls

Shell builtin — Code implemented inside the shell process — pwd is a shell builtinpwd

Shell function — A named block of shell code — name is a function — A user-defined function such as deploy

External executable — An executable file found through PATHgrep is /usr/bin/grepgrep

Not found — No recognized shell entity or searchable executable — name: not found — A misspelled or unavailable command

Checking Common Commands

Check pwd

type pwd

On a typical Bash installation, this identifies pwd as a shell builtin. Shells often provide builtins for commands that need direct access to shell state, such as the current working directory.

Check ls

type ls

This tells you whether ls is an alias, function, builtin, or external executable. Many interactive configurations define an alias that adds color or other display options, but this is not universal.

Check grep

type grep

If grep has not been replaced by an alias or function, the result commonly identifies an executable path such as /usr/bin/grep.

Inspect several names

type cd pwd ls

Multiple names let you compare different resolution categories in one command. For example, cd and pwd are commonly builtins, while ls may be an alias followed by an external executable.

Find All Matches with type -a

The -a option asks supporting shells to display every applicable interpretation or matching executable location instead of only the first result selected by the shell.

type -a ls

A possible result is:

ls is aliased to `ls --color=auto'
ls is /usr/bin/ls
ls is /bin/ls

The selected interpretation normally appears first. Later lines can show executable files in additional PATH directories. This is especially useful when an alias, function, builtin, or earlier PATH directory shadows another command with the same name.

InvocationPurposeWhen to use it

type NAME — Show the interpretation selected for one name — Quickly check a command before running it

type -a NAME — Show all supported interpretations and matching executable locations — Investigate aliases, shadowing, or multiple installed versions

type NAME1 NAME2 — Inspect several names together — Compare command resolution in one shell session

Command Precedence and Shadowing

Shadowing occurs when a higher-priority shell definition prevents a same-named executable from being selected. In practical terms, aliases and other shell-defined entities can take precedence over executables discovered through PATH. The exact lookup order depends on the shell, but aliases, reserved words, functions, builtins, and external commands are all relevant categories.

For example, if ls is an alias, typing ls does not directly select the executable found by searching PATH. If a function named grep exists, that function may run instead of /usr/bin/grep.

The command name you type and the program that ultimately runs can therefore differ. Run type before relying on a familiar name in troubleshooting, administration, or an interactive command. In scripts, prefer deliberate command names and controlled environments when exact behavior matters.

Shell Portability and Limitations

type is commonly available as a builtin in Bash, Zsh, and other shells, but supported options, output wording, and classification categories vary. In particular, the behavior of -a and the descriptions of functions or keywords may differ.

type reflects the current shell session. Changing from Bash to Zsh, starting a shell with different startup files, defining or removing an alias, changing functions, or modifying PATH can change the result.

When exact behavior matters, consult the documentation for the active shell. You can also compare the current environment with related lookup tools such as command -V and command -v, but do not assume their output or precedence behavior is identical to type.

Troubleshooting with type

A familiar command behaves differently

Run:

type COMMAND

If the result identifies an alias or function, that shell definition may be overriding the executable you expected.

The desired executable is not running

Run:

type -a COMMAND

Inspect the complete list. A higher-priority alias or function may shadow the executable, or an executable in an earlier PATH directory may shadow another installed version.

Examples produce different output

Verify the active shell and inspect local aliases, functions, and PATH. Differences commonly result from shell implementation, distribution defaults, startup configuration, or user-defined settings.

type reports that a command is not found

Check the spelling, confirm that the required package or program is installed, and verify that its directory is included in PATH. A command can exist on disk but remain unavailable if its directory is not searchable through the current environment.

Practical Terminal Example

$ type pwd
pwd is a shell builtin

$ type ls
ls is aliased to `ls --color=auto'

$ type -a ls
ls is aliased to `ls --color=auto'
ls is /usr/bin/ls

$ type grep
grep is /usr/bin/grep

These lines show three different ideas: pwd is handled internally, ls is changed by an alias before an external executable is considered, and grep resolves directly to an executable path. Treat these as representative examples, not universal output.

Exam-Relevant Notes

  • Purpose: type reports how the current shell resolves a command name.
  • Shell builtin: A command implemented inside the shell process, such as commonly configured pwd.
  • External command: An executable file located through the ordered directories in PATH.
  • Alias: Shell text substitution that can change a command invocation.
  • Function: A named block of shell code callable as a command.
  • -a: Requests all supported interpretations or matching executable locations, with the selected result normally listed first.
  • Environment matters: Shell choice, startup files, aliases, functions, distribution, and PATH can all change the output.

For broader Linux command-line study, see Bourne Again Shell Bash, Show the Full Path of Shell Commands, and Search for Text Strings Using Grep.