Selective command-history in the terminal?

Solution 1:

It won't show things only starting with ls, but you can do Ctrl-R ls to do a backwards search through history. Repeat Ctrl-R to find the next match.

Solution 2:

Sometimes it's useful to have this...

Example

Connecting to another machine using ssh:

start typing

ssh

Use PgUp key and your ssh ends up with your last used ... press PgUp again and it gives you the next one and so on. Like it?

You can use this:

Edit your .bashrc (vi /home/<yourfolder>/.bashrc) and add this:

$if Bash
    # Search history back and forward using page-up and page-down
    "\e[5~": history-search-backward
    "\e[6~": history-search-forward

    # Completion
    set match-hidden-files off
    set page-completions off
    set completion-query-items 350
    set show-all-if-ambiguous on

$endif

This adds only to your user's terminal this function. You will have to edit also the one of the root to have the same: you can follow this tutorial from the wiki there's no way you can do it wrong, also there is a lot of extra stuff to improve your terminal experience...

Solution 3:

To see the command history, use can use:

$ history

If you only want to see the past command begin with for example "ls", in my opinion I uses:

$ history | grep ls

Certainly the output will contain something not a command but contain "ls" characters, but I think it can help.