Announcement

Collapse
No announcement yet.

Terminal SLASH Konsole users History is a great tool

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Terminal SLASH Konsole users History is a great tool

    I use the terminal a LOT. I just discovered a neat time saver. Say you typed a long command like:

    sudo -u www-data /usr/bin/php /var/www/nextcloud/occ files:scan --all --verbose

    and wanted to use it again, but that was like a half-hour ago so there were hundreds of commands between then and now. Scrolling through them would be more work than typing it all again - assuming of course I remember it correctly.

    Here's the tip: type "history |grep php" and the above command along with a list of other appears like this:

    Code:
    [FONT=monospace][COLOR=#000000]  437  dpkg -l |grep [/COLOR][COLOR=#FF5454][B]php[/B][/COLOR]
    438  [COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000] -v[/COLOR]
    440  sudo -u www-data /usr/bin/[COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000] /var/www/nextcloud/occ files:scan --all --verbose[/COLOR]
    463  locate config.[COLOR=#FF5454][B]php[/B][/COLOR]
    464  nano /var/www/nextcloud/config/config.[COLOR=#FF5454][B]php[/B][/COLOR]
    466  nano /var/www/nextcloud/config/config.[COLOR=#FF5454][B]php[/B][/COLOR]
    468  nano /var/www/nextcloud/config/config.[COLOR=#FF5454][B]php[/B][/COLOR]
    493  nano /var/www/nextcloud/config/config.[COLOR=#FF5454][B]php[/B][/COLOR]
    514  locate Error[COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000].log[/COLOR]
    515  locate Errorlog.[COLOR=#FF5454][B]php[/B][/COLOR]
    517  cat lib/private/Log/Syslog.[COLOR=#FF5454][B]php[/B][/COLOR]
    524  nano /var/www/nextcloud/config/config.[COLOR=#FF5454][B]php[/B][/COLOR]
    526  nano /var/www/nextcloud/config/config.[COLOR=#FF5454][B]php[/B][/COLOR]
    541  apt install [COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000]7.0-pdo[/COLOR]
    542  apt install [COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000]-pdo[/COLOR]
    544  ls /etc/[COLOR=#FF5454][B]php[/B][/COLOR]
    545  ls /etc/[COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000]/7.1[/COLOR]
    546  ls /etc/[COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000]/7.1/apache2/[/COLOR]
    547  rm -rfv /etc/[COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000]/7.1[/COLOR]
    548  ls /etc/[COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000]/7.0[/COLOR]
    549  ls /etc/[COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000]/7.0/apache2/[/COLOR]
    550  ls /etc/[COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000]/7.0/apache2/conf.d/[/COLOR]
    551  ls /etc/[COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000]/7.0/apache2/conf.d/20-mysql.ini[/COLOR]
    552  ls /etc/[COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000]/7.0/apache2/conf.d/20-mysqli.ini[/COLOR]
    553  cat /etc/[COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000]/7.0/apache2/conf.d/20-mysqli.ini[/COLOR]
    554  cat /etc/[COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000]/7.0/apache2/conf.d/20-pdo_mysql.ini[/COLOR]
    555  cat /etc/[COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000]/7.0/apache2/[/COLOR][COLOR=#FF5454][B]php[/B][/COLOR][COLOR=#000000].ini  [/COLOR]
    568  cat /var/www/nextcloud/config/config.[COLOR=#FF5454][B]php[/B][/COLOR]
    606  cat nextcloud/index.[COLOR=#FF5454][B]php[/B][/COLOR]
    613  nano index.[COLOR=#FF5454][B]php[/B][/COLOR]
    626  history |grep [COLOR=#FF5454][B]php[/B][/COLOR]
    
    [/FONT]
    The command I wanted is line 440, so all I have to type is:

    !440

    That's it! Neat!

    Please Read Me

    #2
    That's quite useful. Another tool for the toolbox.
    Windows no longer obstructs my view.
    Using Kubuntu Linux since March 23, 2007.
    "It is a capital mistake to theorize before one has data." - Sherlock Holmes

    Comment


      #3
      Yep! Great one! Have that in my list.

      Comment


        #4
        In a similar vein, in a new install I've always added the following lines to the end of my .bashrc:

        Code:
        # Enable command line history recall navigation filtering by using up and down arrows
        # ala 4dos/NT/TC (obtained from http://www.geocities.com/h2428/petar/bash_hist.htm)
        bind '"\e[A"':history-search-backward
        bind '"\e[B"':history-search-forward
        
        # This gives the equivalent 4Dos/NT/TC Page-Up command to show all previous entered commands based
        # on the partial input on the current line
        bind '"\e[5~"':"\"\C-k\C-ahistory | grep '^ *[0-9]* *\C-e.'\C-m\""
        The comment lines pretty much explain what the commands do. The first one modifies the standard command line recall function to quickly recall previous command lines that started with certain characters, i.e: by typing a few characters of a previously used command and then pressing up or down arrows it finds commands that started with those characters.

        I see the geocities web page has disappeared now, I was just giving credit to the person who came up with it originally. Back in my DOS days I used to use 4DOS, 4NT and Take Command command line interpreters a lot and they had some really advanced features.

        The second one is similar to oshunluvr's history recall function. Type a few characters of a previously used command and press Page Up ... gives a list of indexed commands that started with those characters and you can execute them as with oshunluvr's tip. It only works for command lines that started with those characters unlike oshunluvr's recall function that finds the characters anywhere in the command line. I'm now wondering if I should modify the command to make it work the same way.
        Desktop PC: Intel Core-i5-4670 3.40Ghz, 16Gb Crucial ram, Asus H97-Plus MB, 128Gb Crucial SSD + 2Tb Seagate Barracuda 7200.14 HDD running Kubuntu 18.04 LTS and Kubuntu 14.04 LTS (on SSD).
        Laptop: HP EliteBook 8460p Core-i5-2540M, 4Gb ram, Transcend 120Gb SSD, currently running Deepin 15.8 and Manjaro KDE 18.

        Comment


          #5
          Awesome functionality Rod. I may have to add that here!

          Please Read Me

          Comment


            #6
            It is not exclusive to Konsole. It is found in BASH and can be used in any terminal emulator.
            systemd is not for me. I am a retro Nintendo gamer. consoles I play on are, SNES; N64; GameCube and WII.
            Host: mx Kernel: 4.19.0-6-amd64 x86_64 bits: 64 compiler: gcc v: 8.3.0 Desktop: Trinity R14.0.8 tk: Qt 3.5.0 info: kicker wm: Twin 3.0 base: Debian GNU/Linux 10

            Comment

            Working...
            X