|
`type` doesn't just check one path - it searches through your entire `$PATH` (all directories listed in your PATH environment variable) to find the executable.
But here's what makes `type` even better than `which` or `command -v`:
What `type` actually does:
1. Searches every directory in your `$PATH` in order
2. Tells you the first match it finds (the one that would actually run if you typed the command)
Why `type` is better than `which`:
| Command |
What it checks |
| `which` |
Only checks `$PATH` (and sometimes has issues with aliases) |
| `command -v` |
Only checks `$PATH` and built-ins |
| `type` |
Checks everything in this order: |
|
1. Aliases |
|
2. Shell keywords (like `if`, `for`) |
|
3. Shell built-ins (like `cd`, `echo`) |
|
4. Functions |
|
5. Executables in `$PATH` |
See it in action:
Check where 'ls' really comes from
type ls
Output: ls is aliased to `ls --color=auto'
(shows alias BEFORE PATH!)
type echo
Output: echo is a shell builtin
type -a python
Shows ALL matches (not just the first one!)
type -a python3
Shows ALL matches (including aliases!)
Cool flags to know:
- `type -a` -> Shows all matches in search order (super useful!)
- `type -t` -> Shows only the type (alias, keyword, builtin, function, or file)
- `type -p` -> Only shows the path if it's a file in `$PATH` (like `which`)
Try this:
See EVERY place vi might be found
type -a vi
This will show you if it's aliased, if it's a built-in, and every executable path in your `$PATH` that matches "vi" - in the exact order your shell would use them!
`type` checks ALL your paths, but it's actually a "command detective" that looks at everything the shell knows about.
|