Red Hat Certified System Administrator RHCSA · Free Practice Question Medium

Question 11

On ServerB, configure the bash history to store the last 1000 commands entered.

  • Requirements:

    • Configure the bash history to retain the last 1000 commands for easier command recall and auditing.

    • Ensure the changes are applied to the global bash configuration so they affect all users.

    • Verify that the history settings have been correctly applied.

  • A

    Pass

  • B

    Fail

Reveal correct answer

Correct answer: A

Explanation

Answer:

  1. Edit the Global Bash Configuration File:

    • Explanation: Editing /etc/bashrc applies the configuration globally, ensuring all users on the system can benefit from the updated history settings. If configuring for a single user, these changes could alternatively be made in the user’s ~/.bashrc file.

  2. Add the Following Lines to Configure History Size:

    • Set HISTSIZE:

    • Explanation:

      • HISTSIZE: Defines the maximum number of commands stored in the current session’s command history. When the session reaches 1000 commands, the oldest commands are removed to make space for new entries.

      • Benefit: Increases accessibility to previous commands, making it easier to recall and reuse them.

    • Set HISTFILESIZE:

    • Explanation:

      • HISTFILESIZE: Specifies the maximum number of commands that can be saved to the persistent history file (usually ~/.bash_history). When this file reaches 1000 commands, the oldest entries are deleted to make space for new ones.

      • Difference: While HISTSIZE affects only the active session, HISTFILESIZE controls the persistent storage of commands across sessions.

  3. Save and Exit the File:

    • Press Esc, then type :wq and press Enter to save changes and close vim.

  4. Apply the Changes Immediately:

    • Explanation: Running source /etc/bashrc reloads the bash configuration, applying changes immediately without needing a new session. This ensures that HISTSIZE and HISTFILESIZE are active right away.

  5. Verify the New Settings:

    • Display HISTSIZE:

    • Display HISTFILESIZE:

    • Explanation: Verifying the values of HISTSIZE and HISTFILESIZE confirms that the changes were applied correctly.

Additional Notes:

  • Understanding History Environment Variables:

    • HISTSIZE vs. HISTFILESIZE:

      • HISTSIZE limits the number of commands stored in memory for the current session.

      • HISTFILESIZE limits the total number of commands stored persistently in ~/.bash_history, affecting commands available after reboot or logout.

    • Related Variables:

      • HISTFILE: Specifies the location of the bash history file (typically ~/.bash_history).

      • HISTCONTROL: Controls how duplicate and whitespace-prefixed commands are handled in the history list. Useful values include ignoredups (ignores duplicate commands) and ignorespace (ignores commands prefixed with a space).

  • Practical Applications:

    • Session Commands: Increasing HISTSIZE allows you to review a more extensive list of commands within a session, useful for troubleshooting or complex workflows.

    • Auditing and Security: Setting HISTFILESIZE helps maintain a historical record of commands, beneficial for security auditing or reviewing command patterns.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need