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:
Edit the Global Bash Configuration File:
- # vim /etc/bashrc
Explanation: Editing
/etc/bashrcapplies 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~/.bashrcfile.
Add the Following Lines to Configure History Size:
Set HISTSIZE:
- export HISTSIZE=1000
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:
- export HISTFILESIZE=1000
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
HISTSIZEaffects only the active session,HISTFILESIZEcontrols the persistent storage of commands across sessions.
Save and Exit the File:
Press
Esc, then type:wqand pressEnterto save changes and closevim.
Apply the Changes Immediately:
- # source /etc/bashrc
Explanation: Running
source /etc/bashrcreloads the bash configuration, applying changes immediately without needing a new session. This ensures thatHISTSIZEandHISTFILESIZEare active right away.
Verify the New Settings:
Display HISTSIZE:
- # echo $HISTSIZE
Display HISTFILESIZE:
- # echo $HISTFILESIZE
Explanation: Verifying the values of
HISTSIZEandHISTFILESIZEconfirms 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) andignorespace(ignores commands prefixed with a space).
Practical Applications:
Session Commands: Increasing
HISTSIZEallows you to review a more extensive list of commands within a session, useful for troubleshooting or complex workflows.Auditing and Security: Setting
HISTFILESIZEhelps 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.
