Use an interactive Bash with history enabled.
Display the last five commands with their history numbers.
Which command is correct?
Passing a number to history displays that many entries from the end of the history list, including their numbers.
Detailed explanation
history 5Correct. history 5 prints the five most recent entries.
Correct. history 5 prints the five most recent entries.
history -c 5Incorrect. -c clears the history; it is not a count option.
Incorrect. -c clears the history; it is not a count option.
history -d 5Incorrect. -d deletes one history entry at the specified offset.
Incorrect. -d deletes one history entry at the specified offset.
history -w 5Incorrect. -w writes history to the history file.
Incorrect. -w writes history to the history file.
Try it yourself
An example you can run in a temporary verification environment.
対話的Bashでhistory 5を実行するExpected result
直近5件の履歴番号とコマンドKey points
- Interactive Bash history
- The count argument to history
- History numbers
Notes
- Environment: Bash 5.2(対話モード)
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.