See past commands with history and which
Replay what you typed with history, and find where a command lives with which.
Start Interactive LessonWhen you forget the exact command you ran five minutes ago, Bash already stored it. history prints that list. which answers a different question: which executable will run if you type a name.
List what you already typed
Run history with no extra arguments. Each line starts with a number, then the command.
Try the command
Show the commands you already ran!
Read the session log:
The numbers are useful later with !n replay, but the first skill is simply reading the list so you can copy a command that already worked.
Find where a command lives: which
which echo prints the path of the echo program the shell will run. That tells you whether you are using a builtin, a system binary, or a custom script that shadowed the name.
which echo
Typical output is /usr/bin/echo or a similar path. If which prints nothing, the name is not on your PATH.
Use history to remember what you did. Use which when two tools share a name and you need to know which one actually runs.
Knowledge Check
1 / 3What does history show?
References
These documentation links provide authoritative details for the commands used in this article.
Up Next
Chain navigation and listing in one move to verify route and destination state.