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 pageSample 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.gzHow it works: file, alias or builtin
Not every command is a program on disk.
cdis built into the shell (a builtin),llis usually an alias, andlsis a program file on thePATH.whichonly looks for a file in thePATHdirectories and knows nothing about builtins or aliases.typedoes: it tells you exactly what a command is, and that is the most honest answer.whereisalso finds themanpage and the sources. When it is unclear why the wrong command runs, start withtype.
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.