type / command
Overview
type explains how the shell will resolve a name — alias, keyword, function, builtin, or external file. command runs a program bypassing functions/aliases of the same name (and can query paths). Together they answer: “Why did that run?” when which alone misleads (it ignores builtins/aliases depending on setup).
Syntax
type [-afptP] name [name...]
command [-pVv] command [arg...]Common Options
type (bash)
| Option | Description |
|---|---|
-a |
All locations / matches |
-t |
Single word: alias, keyword, function, builtin, file |
-p |
Path to disk executable if file |
-P |
Force path search even if non-file |
-f |
Suppress function lookup |
command
| Option | Description |
|---|---|
-v / -V |
Describe command (similar spirit to type) |
-p |
Use default PATH search |
| (default) | Execute, skipping shell functions/aliases |
Examples with Explanations
What is this name?
type ls
type type
type echo cd time
type -a python3Typical: ls is aliased to …, echo is a shell builtin, python3 is /usr/bin/python3.
Machine-readable kind
type -t ls
# alias
type -t mkdir
# fileUseful in scripts choosing behavior.
Path only
type -p sha256sum
# /usr/bin/sha256sumEmpty if pure builtin/alias without a file.
Run without alias/function
command ls # unaliased ls
command -v ls
command -p lsCompare to which / command -v
which ls
type ls
command -v lswhich is an external program and can disagree with the shell’s true resolution — prefer type/command -v inside bash.
Debug “wrong binary”
type -a node
echo "$PATH"Multiple file hits show PATH order; the first is used for external commands.
Notes
- Keywords (
if,for) are not executables —typereportskeyword. - Hashed paths: bash caches external locations (
hash); after moves,hash -rrefreshes. commandis also the safe way to call externals from functions named the same.- Dash/
shmay have fewertypefeatures — checkhelp typein your shell.
Additional Resources
help type,help commandman bash