๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

๐Ÿ“œ Shell Scripting October 16, 2026 13

Linux Command: history

Display or manipulate command history

Terminal โ€” Shell Scripting
Command
$ history 20
Output
151 git status\n 152 git add .\n 153 git commit -m "fix"

history displays the command history list, showing previously executed commands with their line numbers. It allows you to search, recall, and re-execute past commands, dramatically increasing shell productivity. Bash stores command history in memory during a session and saves it to ~/.bash_history on exit. The HISTSIZE variable controls how many commands are kept in memory, and HISTFILESIZE controls the file size. history supports searching (Ctrl+R), re-execution (!N, !!), and editing. Mastering history navigation is one of the biggest productivity gains for Linux users.

Syntax

history [OPTION]... [N]

Key Options

  • N โ€” Show last N commands
  • -c โ€” Clear the history list
  • -d N โ€” Delete entry number N
  • -w โ€” Write history to file
  • -r โ€” Read history from file
  • -a โ€” Append new entries to history file

Examples

Show recent commands

history 20

Output: 151 git status\n 152 git add .\n 153 git commit -m "fix"

Search history

history | grep ssh

Output: 45 ssh user@server1\n 89 ssh admin@server2

Re-execute last command

!!

Pro Tips

  • Press Ctrl+R and type to search backwards through history. Press Ctrl+R again to find older matches. Enter to execute, Ctrl+G to cancel.
  • Forgot sudo? Type sudo !! to re-run the last command with sudo. !! is replaced with the previous command.
  • Commands with passwords appear in history. Use HISTCONTROL=ignorespace and prefix sensitive commands with a space to exclude them.

Learn more: Full history reference โ†’

Share this tip