Shell and environment

Command history

Show command history

Linux · Bash examples · commands run on the selected server

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

N
Show the latest N entries in Bash.
-a
Add new session records to the history file.
-r
Read entries from the history file.

Usage examples

View latest commands

history 20

A bounded recent portion of shell history is displayed.

Find SSH commands in history

history | grep -F ssh

Recorded entries containing the literal search text are selected.

Save new session entries

history -a

New 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.