There are many commands in the console that periodically need to be executed, for example sudo tail -f /var/log/fail2ban.log I open periodically, I look. It happens that you need to look again, for example, sudo tail -f /var/log/fail2ban.log and you start with the up arrows - scroll through the history of commands until you find the right one.

Maybe there is some kind of "thing" where I would add commands and what is called, with one click would call the ones I need? Like a bookmark bar in the browser.

  • one
    Creating alias in linux doesn't suit your needs? - RTK
  • IMHO is best to configure inputrc correctly and then in all readline-based interpreters (including bash) you can “flip through” commands on the command line already written using PgUp / PgDown ... - Fat-Zer

2 answers 2

The following describes a bash program that uses the readline library to edit input lines and manipulate command history:

  1. press ctrl + r , start entering an arbitrary part of the text of any of the commands stored in the history. the most recent command that matches is displayed. By pressing ctrl + r repeatedly, find earlier commands that match the same match.

    reverse search (to more “new” commands) is performed by ctrl + s by default, but, unfortunately, by default this combination is used by the terminal itself ( tty device) as the stop output command stop (resume output — give the terminal a start command using ctrl + q , see the output of $ stty -a ). that is, to use ctrl + s, you need to adjust the settings of either the terminal or the readline library.

  2. The history of teams can be scrolled not only “one at a time” with up / down arrows, but also with the help of readline- new commands history-search-backward and history-search-forward . unfortunately, by default, they are not tied to any shortcut (in some distributions they do do this binding). To bind them to keys, for example, pageup / pagedown , add such lines to ~/.inputrc (user configuration file of the readline library) (for the changes to take effect, you must start a new bash process):

     "\e[5~": history-search-backward "\e[6~": history-search-forwar 

    if now in the command line you enter several characters of the beginning of the command you are looking for, then by pressing pageup / pagedown , you can “walk” through the entire list of commands that begin with these characters.

    Ctrl + r - reverse search in history (for more information on keyboard shortcuts on the command line, see documentation 1 , 2 for the readline library).

    You can save individual commands as alias ' s or, for more complex structures, in scripts. It is also worth learning how to use screen .

    In summary, read a book, for example, the famous Evie Nemeth UNIX: System Administrator's Guide . This year, by the way, a new edition has been released.