~2 min read • Updated Jul 18, 2025

Introduction


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.


The type Command – Identifying Command Type


type is a shell builtin that reports whether a command is a builtin, an alias, or an external executable.


Basic Syntax


type command

Examples


CommandResult
type typetype is a shell builtin
type lsls is aliased to ls --color=tty
type cpcp is /bin/cp

Key Insights


  • Builtins: Internal commands like type, cd, etc.
  • Aliases: Custom shortcuts such as ls --color=tty
  • Executables: External programs like /bin/cp

The which Command – Locating Executables


which is an external program that returns the full path of an executable command as it appears in the current PATH.


Basic Syntax


which command

Examples


CommandResult
which ls/bin/ls
which cdNo result – cd is a builtin

Key Insights


  • Works only for executable programs—not builtins or aliases
  • Useful for identifying the exact version of a command being executed
  • Important in multi-environment or multi-path setups

type vs which – Comparison Table


Featuretypewhich
Identify if command is builtin, alias, or executable✔️
Return full path of executable✔️
Works with builtins and aliases✔️
Useful for shell behavior analysis✔️✔️

Conclusion


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.


Written & researched by Dr. Shahin Siami