Basics

Linux history command

Show commands recorded by your shell in the current history list.

Availability: Common Linux commands; shell built-ins and external implementations may differ by distribution.中文

Syntax

history [N] | history [-c] | history [-d OFFSET]

Examples

Show the most recent 20 commands.

history 20

Show the last ten displayed history lines.

history | tail -n 10

Parameters, options and clauses

Option / clauseDescription
NShow the most recent N history entries.
-cClear the in-memory history list.
-d OFFSETDelete the history entry at OFFSET.
-aAppend new entries from this session to the history file.
-rRead the history file and append its contents to the list.
-wWrite the current list to the history file.
Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory