CMD Master
Back to Blog
Arnošt Havelka

See past commands with history and which

Replay what you typed with history, and find where a command lives with which.

Start Interactive Lesson
See past commands with history and which

When 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!

Build the command
history
Terminal
C:\Users\User>history

Read the session log:

Command Prompt
Hello terminal
C:\Users\User>echo Hello terminal

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.

Command Prompt
C:\Users\User>which echo

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 / 3

What does history show?

References

These documentation links provide authoritative details for the commands used in this article.

Up Next

Change folders in Bash with cd

Jump to /, step up with .., and go home with ~ using the Bash cd command.