When to use history
Use history to inspect commands recorded by an interactive shell. Treat it as potentially sensitive convenience data, not a complete audit trail, because recording rules and persistence depend on shell configuration.
Syntax
history [PARAMETERS] [NUMBER]Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.
Common options and arguments
Usage examples
View latest commands
history 20A bounded recent portion of shell history is displayed.
Find SSH commands in history
history | grep -F sshRecorded entries containing the literal search text are selected.
Save new session entries
history -aNew entries from the current session are appended to the configured history file.
Notes and limitations
- Built-in command Bash; The format and behavior of other shells are different.
- History may contain secrets. Deleting a local entry does not revoke an already revealed password or token.
Common questions and troubleshooting
Why is a command missing from history?
Recording filters, disabled history, another shell or unsaved session data can explain omissions. History is not proof that an action never occurred.
Can saving a secret command expose it later?
Yes. Avoid typing secrets into command arguments. Use appropriate interactive prompts, credential stores or protected input mechanisms.
Further help
Options vary by version and distribution. Check the installed documentation with this command: help history.