which, type, whereis in Linux: where a command lives

Updated November 1, 2026

which, type and whereis answer where a command lives and what it is.

Common cases

which bash       # the path to the program file in PATH
type cd          # cd is a shell builtin
type ll          # shows if it is an alias
whereis ls       # the program and its man page

Sample output

$ which bash
/usr/bin/bash
$ type cd
cd is a shell builtin
$ type -a ls
ls is aliased to `ls --color=auto'
ls is /usr/bin/ls
ls is /bin/ls
$ whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

How it works: file, alias or builtin

Not every command is a program on disk. cd is built into the shell (a builtin), ll is usually an alias, and ls is a program file on the PATH. which only looks for a file in the PATH directories and knows nothing about builtins or aliases. type does: it tells you exactly what a command is, and that is the most honest answer. whereis also finds the man page and the sources. When it is unclear why the wrong command runs, start with type.

Common mistakes

which cd prints nothing and returns 1. No error, no explanation, and from the outside it looks as if cd is missing from the system, while it is there in every shell. type cd answers cd is a shell builtin. Read an empty which answer as "no file by that name in PATH", not as "no such command".

The shell remembers where a command lives and keeps going to the old address after you move the file. Move ~/bin/mytool to your home directory and mytool answers bash: /home/student/bin/mytool: No such file or directory. The full path in the message is the clue: you typed a short name, and bash filled in the path it had cached. type mytool confirms it: mytool is hashed (/home/student/bin/mytool). hash -r clears that memory.

whereis looks in system directories and in PATH, not across the whole disk. For a script that sits in /tmp/tools it answers mytool: with nothing after the colon and no error at all. An empty answer means "not where I look"; to search the whole filesystem you need find.

Used in

You need this in the lessons Finding files and Getting help. The theory is the chapter Getting help: man and --help.

See also

The locate command, The find command, The PATH variable.

Try it

Open the sandbox: a real throwaway Linux terminal in your browser. Run the commands above by hand - the container is deleted when you leave.