Enhancing Skills

history: Command History Management

history: Display or manipulate the command history list.

Description: Shows the list of commands previously executed in the shell. Useful for recalling and reusing commands without retyping them.

  • Basic Usage:
  history
  • Common Arguments:
  • -c: Clear the history list.
  • -a: Append the new history lines (from the current session) to the history file.
  • -r: Read the history file and append its contents to the history list.
  • -w: Write the current history list to the history file.
  • Executing a Specific History Command:
    To execute a specific command from your history, use the ! operator followed by the history number of the command you want to run. Example:
  !3

This will execute the command listed as number 3 in the history list.

  • Sample Command and Output: Command:
  history

Output:

    1  ls
    2  cd /var/log
    3  cat syslog
    4  grep error syslog
    5  history

Command to Execute a Specific History Entry:

  !3

Output:

  cat syslog

Using history in combination with ! allows for quick execution of previously used commands, enhancing productivity and ease of use in the terminal.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.