How to View and Reuse Past Commands in Linux (history)

The history command lists previously executed shell commands, and integrates with shortcuts for quickly reusing them.

Published October 1, 2026

The history command lists previously executed shell commands, and integrates with shortcuts for quickly reusing them.

Key points

  • Run !! to instantly re-run the previous command, often combined with sudo (sudo !!)
  • !123 re-runs the command numbered 123 in the history list
  • Command history is normally stored per-shell-session and written to a history file (like ~/.bash_history) on exit

Example

history | grep docker
More Linux articles