The history command in Red Hat Linux records previously executed commands, helping users recall past actions, troubleshoot issues, and monitor system activity.


Using the history Command

To view saved commands:

history

Each command appears with a number for easy reference.

To rerun a specific command:

!n

Replace n with the command number.


Why It Matters

  • Saves Time – Quickly reuse past commands.
  • Fix Mistakes – Modify and rerun incorrect commands.
  • Tracks Activity – Helps administrators monitor user actions.

To repeat the last command:

!!

To rerun a command that starts with a specific word:

!keyword

Managing History

To remove all stored commands:

history -c

To delete a specific entry:

history -d n

Replace n with the command number.

For permanent deletion:

cat /dev/null > ~/.bash_history

Storing Command History

To ensure command logs are saved:

echo 'export HISTFILE=/var/log/bash_history' >> ~/.bashrc
source ~/.bashrc

This stores command history in /var/log/bash_history for tracking.


Conclusion

The history command is a valuable tool for efficiency, troubleshooting, and security. Learning to use it effectively simplifies Linux management and keeps systems running smoothly.