Advanced Commands: history - Command History

Every time we run a command, that’s memorized in the history.

You can display all the history using:

history

This shows the history with numbers:

You can use the syntax !<command number> to repeat a command stored in the history, in the above example typing !121 will repeat the ls -al | wc -l command.

Typically the last 500 commands are stored in the history.

You can combine this with grep to find a command you ran:

history | grep docker

To clear the history, run history -c

The history command works on Linux, macOS, WSL, and anywhere you have a UNIX environment

Lessons in this unit:

0: Introduction
1: su - Switch User
2: sudo - Superuser Do
3: passwd - Change Password
4: ping - Test Network
5: traceroute - Trace Network Path
6: ▶︎ history - Command History
7: export - Set Environment Variables
8: crontab - Schedule Tasks
9: alias - Create Shortcuts
10: man - Manual Pages
11: tar - Archive Files
12: gzip - Compress Files
13: gunzip - Decompress Files
14: basename - Strip Directory
15: dirname - Extract Directory
16: nano - Text Editor
17: vim - Vi Improved Editor
18: emacs - Text Editor
19: ed - Line Editor

Join my AI Workshop!

The Web Development BOOTCAMP cohort starts in February 2026