dgt_bash03 – Command History

Module Title: dgt_bash03 – Command History

Overview:
“dgt_bash03 – Command History” covers the Bash command history features. It is intended both for experienced shell users and for those new to the command line, and explains how Bash records, stores and recalls the commands run in a session, so that participants can read, reason about and direct shell work.

Approach:
You first learn how history works under the hood: the history list in memory, the history file, the variables that shape it and the expansion syntax. Then, in practice, you do not type those commands yourself. You ask the machine in plain language, for example “keep the last 10,000 commands, skip duplicates and never save lines that start with a space”, read the configuration it proposes, and check that it matches what you know about HISTCONTROL and the history file before accepting it.

Module Objectives:
By the end of this module, participants will be able to:

  1. Understand the fundamentals of Bash command history.
  2. Describe precisely to the machine how command history should be controlled, and verify the settings it applies.
  3. Ask the machine to search the history for past operations and judge whether the results are complete and correct.
  4. Read and explain the history expansions the machine uses to re-execute commands, and spot risky ones before they run.

Module Content:

  1. Introduction to Command History
  2. Overview of what command history is in Bash.
  3. The significance of command history for efficiency, productivity and auditing what was done on a system.

  4. Controlling Command History

  5. How to append vs. overwrite the command history file.
  6. Understanding the .bash_history file and its configuration options.
  7. Configuring shell settings e.g., HISTSIZE, HISTCONTROL to manage history behavior.
  8. Practical examples of enabling/disabling commands in history with HISTIGNORE.

  9. Navigating Command History

  10. Using basic navigation keys Up/Down Arrow and shortcuts like the reverse search feature Ctrl + R.
  11. Executing previous commands using numeric indexing e.g., !n.

  12. Searching Commands in History

  13. Techniques for searching through command history with pattern matching.
  14. How incremental search works and how it refines a search as you go.
  15. Practical examples in which you ask the machine to find specific commands and verify what it found.

  16. Executing Commands from History

  17. Re-executing commands using history expansion techniques e.g., !!, !$.
  18. Modifying and re-running previous commands with !:n, !?string?.
  19. Real-world scenarios in which you read the expansions the machine proposes and confirm they do what you intended.

  20. Advanced Tips and Tricks

  21. Customizing Bash prompts to include history information.
  22. Integrating command history with other shell features like aliases and functions.
  23. Best practices for maintaining a clean, useful history log.

Target Audience:
This module is intended for system administrators, DevOps professionals, developers, and anyone who works with Linux systems. It is also suitable for IT students who want to understand the shell well enough to direct an AI agent on it and review its work.

Assessment:
Participants are assessed through practical exercises in which they instruct the machine, in natural language, to control, search and reuse the command history, then explain and verify every command and setting it produced.

The students can push their exercises to the Academy DevOps & SRE Git project. For this module, create a folder with your username as its name in the following subfolder: https://github.com/Garanti-Del-Talento/gdt_academy