Understanding how commands are interpreted in the Linux shell is crucial for managing scripts, resolving conflicts, and analyzing system behavior. Linux provides two helpful tools for this purpose: type
and which
. Each offers a distinct perspective—type
reveals how the shell classifies a command, while which
shows where an executable resides on the file system.
type
is a shell builtin that reports whether a command is a builtin, an alias, or an external executable.
type command
Command | Result |
---|---|
type type | type is a shell builtin |
type ls | ls is aliased to ls --color=tty |
type cp | cp is /bin/cp |
type
, cd
, etc.ls --color=tty
/bin/cp
which
is an external program that returns the full path of an executable command as it appears in the current PATH
.
which command
Command | Result |
---|---|
which ls | /bin/ls |
which cd | No result – cd is a builtin |
Feature | type | which |
---|---|---|
Identify if command is builtin, alias, or executable | ✔️ | ❌ |
Return full path of executable | ❌ | ✔️ |
Works with builtins and aliases | ✔️ | ❌ |
Useful for shell behavior analysis | ✔️ | ✔️ |
Both type
and which
are valuable for understanding command behavior in Linux. Use type
to determine a command’s classification within the shell—whether it's builtin, alias, or executable. Use which
when you need to locate the actual executable file. These tools are particularly helpful in debugging, scripting, and system administration.