Skip to main content

Command referencehistory

history command (Linux / bash / sh / zsh)

Linuxbashshzshotherbeginner

What it does

Display or modify the current shell's command history. When people search for the history command linux shell, they usually want history's everyday flags, safe examples, and how it differs from related tools. Below you'll find syntax, options, and copyable examples for Bash/sh/zsh.

Display or modify the current shell's command history.

Syntax

history [N] | history [OPTION]

Common options

Flag / optionMeaning
NShow only the last N entries.
-cClear the in-memory history list.
-d OFFSETDelete one history entry.
-wWrite current history to the history file.

Practical examples

Recent commands

history 20

Shows the last twenty history entries.

Search history

history | grep docker

Finds previous commands mentioning Docker.

Remove sensitive entry

history -d 123

Deletes history entry 123 from the current list.

Common mistakes

  • Assuming deletion from memory also rewrites the history file immediately.
  • Entering secrets on command lines where shell history can retain them.

FAQ

What does history do in Linux?

Display or modify the current shell's command history.

How do I use history from the terminal?

Start with `history [N] | history [OPTION]`, then choose only the options needed for the task.

What is a practical history example?

Try `history 20` — Shows the last twenty history entries.

Can I use history in a shell script?

Yes. history works in Bash, sh, and Zsh, but scripts should handle quoting, errors, and command output explicitly.

Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.