DEV Community

Cover image for How to highlight and see a specific command that was executed in the Linux terminal?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

How to highlight and see a specific command that was executed in the Linux terminal?

Originally posted here!

To highlight and see a specific command that was executed in the Linux terminal, we can use the history command followed by the | operator (pipe operator), then the grep command and, the name of the command we need to see highlighted.

# Highlight and see specific command was executed
history | grep <YOUR_COMMAND_TO_HIGHLIGHT>
Enter fullscreen mode Exit fullscreen mode

For example, let's say we need to highlight and see whether the ls command was executed in the terminal. To do that we can use the history and the grep command like this,

# Highlight and see specific command was executed
history | grep ls
Enter fullscreen mode Exit fullscreen mode

The above commands do the following operations:

  • First, The history command will get all the commands executed in the terminal.
  • The output of the history command is then piped into the grep command and then the grep command will highlight the all ls commands which were executed.

The output of the above command may look like this,

ls command being highlighted

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

That's all 😃!

Feel free to share if you found this useful 😃.


Top comments (0)