history

history: The history command in Linux displays a list of the commands you have entered in the current shell session or in previous sessions. This list is typically numbered, showing the most recent commands at the bottom.

Basic Usage:

  • history: Displays the list of commands you’ve executed, along with their corresponding command numbers.

Common Options:

  • history <n>: Shows the last n commands.
  • Example: history 10 displays the last 10 commands.
  • !<number>: Re-executes a command from the history list by its number.
  • Example: !42 re-runs command number 42 from your history.
  • !!: Repeats the last command you executed.
  • Example: If your last command was ls -l, typing !! will execute ls -l again.
  • history -c: Clears the entire history list for the current shell session.

Example:

history
# Output:
# 1  cd /home/user
# 2  ls
# 3  pwd
# 4  history

In this example, the history command shows the list of commands you’ve run, such as cd, ls, and pwd.

The history command is useful for recalling past commands, reusing complex command sequences, and improving efficiency in the shell.

Leave a Reply

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