Mastering the `history` Command in Red Hat Linux: Tracking and Managing Commands
Alexand

Alexand @axisinfo_0a61830e06c3c950

About: I'm an IT enthusiast passionate about networking, systems integration, cybersecurity, and data analytics. I aim to build secure, data-driven solutions that protect businesses and drive innovation.

Location:
Germany
Joined:
Jul 13, 2024

Mastering the `history` Command in Red Hat Linux: Tracking and Managing Commands

Publish Date: Apr 30
0 0

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
Enter fullscreen mode Exit fullscreen mode

Each command appears with a number for easy reference.

To rerun a specific command:

!n
Enter fullscreen mode Exit fullscreen mode

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:

!!
Enter fullscreen mode Exit fullscreen mode

To rerun a command that starts with a specific word:

!keyword
Enter fullscreen mode Exit fullscreen mode

Managing History

To remove all stored commands:

history -c
Enter fullscreen mode Exit fullscreen mode

To delete a specific entry:

history -d n
Enter fullscreen mode Exit fullscreen mode

Replace n with the command number.

For permanent deletion:

cat /dev/null > ~/.bash_history
Enter fullscreen mode Exit fullscreen mode

Storing Command History

To ensure command logs are saved:

echo 'export HISTFILE=/var/log/bash_history' >> ~/.bashrc
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

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.

Comments 0 total

    Add comment