which, type & snap
Locate the program behind a command, and meet the universal snap package format.
Syntax
which command
type command
command -v commandWhen you type a command, how does the shell find the program? These tools tell you.
which & type
which python3— prints the full path of the program that will run.type ls— says whether a name is a program, a shell builtin, or an alias.command -v git— a portable way to check if a command exists (handy in scripts).
snap
snap is a newer, distro-independent package format from Ubuntu. Snaps bundle all their dependencies, so the same package works everywhere, at the cost of larger size.
sudo snap install code --classic— install a snap.snap list— show installed snaps.
Example
# Where does this command live?
which python3
# /usr/bin/python3
# What kind of thing is 'll'?
type ll
# ll is aliased to `ls -alF'
# Install a snap package
sudo snap install htopWhen to use it
- A developer runs 'which python3' to confirm the active Python binary path when multiple versions are installed.
- A sysadmin uses 'type ls' to discover that 'ls' is aliased to 'ls --color=auto' before scripting with it.
- A DevOps engineer runs 'which kubectl' in a CI container to verify the tool is on PATH before running deploy commands.
More examples
Locate a command binary
Uses which to find the full path of executables on PATH, useful when multiple versions may be installed.
which python3
# /usr/bin/python3
which nginx
# /usr/sbin/nginx
# Check if a command exists at all
which nonexistent || echo 'not found'Inspect command type
Shows how 'type' distinguishes between aliases, shell builtins, and external binaries, unlike 'which'.
type ls
# ls is aliased to 'ls --color=auto'
type cd
# cd is a shell builtin
type python3
# python3 is /usr/bin/python3Find all instances on PATH
Uses -a to reveal all instances of a command across PATH, helping resolve version conflicts.
# -a shows ALL matches, not just the first
which -a python
# /usr/bin/python
# /usr/local/bin/python
# type -a does the same
type -a python
Discussion