Command referencehistory
history command (Linux / bash / sh / zsh)
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 / option | Meaning |
|---|---|
| N | Show only the last N entries. |
| -c | Clear the in-memory history list. |
| -d OFFSET | Delete one history entry. |
| -w | Write 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.
Related commands
- grepSearch text for lines matching a pattern.
- manRead installed manual pages for commands, formats, and APIs.
- echoWrite arguments and shell-expanded values to standard output.
- Get-CommandDiscover commands, aliases, functions, scripts, and applications available to PowerShell.
- ForEach-ObjectRun a script block for each object arriving through the pipeline.
- Get-HelpDisplay syntax, parameter details, examples, and conceptual PowerShell help.
- clsClear visible text from the Command Prompt screen.
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.