How to see only the specified number of commands executed so far or the history of commands executed in the Linux terminal?

August 10, 2021 - 1 min read

To see only the specified number of commands instead of seeing all the commands executed you can use the history command followed by the number of commands you want to see that were executed in the Linux terminal.

TL;DR

# See only the specified count of recent commands
history <COUNT_OF_LAST_COMMANDS_TO_SEE>

For example, let's say we want to see only the recent 5 commands executed in the Linux terminal, we can use the history command like this,

# See the last or recent 5 commands
# executed in the Linux terminal
history 5

See the execution of the above command live in repl.it

NOTE: In some Linux distributions I have found that running the history command followed by the number shows all the commands from history. If it's not working try adding a - (minus) sign before the number like this,

# See the recent 5 commands executed
# for some Linux distributions
history -5

That's all 😃!

Feel free to share if you found this useful 😃.