DEV Community

Cover image for How to see only the specified number of commands executed so far or the history of commands executed in the Linux terminal?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

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

Originally posted here!

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>
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

That's all 😃!

Feel free to share if you found this useful 😃.


Top comments (0)