Ubuntu – Making reverse-incremental-search in terminal easier using comments

bashbash-historycommand line

When you press Ctrl+r in terminal this leads to use the reverse-incremental-search mode.

The reverse-i-search lets you search for previous commands in your terminal, but this can get confusing when you use the same command with different options and become exhausting to search for your needed command.

How can I distinguish between the commands easily, or mark a particular command?

Best Answer

# in some configuration files and programming languages marks comments and is excluded from execution.

Run a command and then create a hashtag using # of the command so that we can find it later.

some-command #mycommand

for example:

sudo dmidecode | grep -A 9 "System Information" #sysInfo

Now I create a hash tag #sysInfo for the command sudo dmidecode | grep -A 9 "System Information" which is used to show system information.

Now search for the hash tag in reverse-i-search (press ctrl+r), in the terminal and type #sysInfo.

You may create as many hash tags for every command and find it later using reverse-i-search.

Note: hashtag used here is not really the same concept as we know in social media. This word is just used to clarify and make it easy for newbies to understand the answer.

source