How do I clear the Gnome terminal history?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
58
down vote

favorite
21












When we use clear command or Ctrl+L in terminal, it clears terminal but we can still scroll back to view the last used commands. Is there a way to completely clear the terminal?










share|improve this question























  • It's terminal dependent, and none of the answers address that.
    – Thomas Dickey
    Oct 19 '16 at 1:11














up vote
58
down vote

favorite
21












When we use clear command or Ctrl+L in terminal, it clears terminal but we can still scroll back to view the last used commands. Is there a way to completely clear the terminal?










share|improve this question























  • It's terminal dependent, and none of the answers address that.
    – Thomas Dickey
    Oct 19 '16 at 1:11












up vote
58
down vote

favorite
21









up vote
58
down vote

favorite
21






21





When we use clear command or Ctrl+L in terminal, it clears terminal but we can still scroll back to view the last used commands. Is there a way to completely clear the terminal?










share|improve this question















When we use clear command or Ctrl+L in terminal, it clears terminal but we can still scroll back to view the last used commands. Is there a way to completely clear the terminal?







terminal command-history gnome-terminal escape-characters






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 3 at 13:01









Neil G

1538




1538










asked Dec 16 '11 at 13:18









hpn

66151420




66151420











  • It's terminal dependent, and none of the answers address that.
    – Thomas Dickey
    Oct 19 '16 at 1:11
















  • It's terminal dependent, and none of the answers address that.
    – Thomas Dickey
    Oct 19 '16 at 1:11















It's terminal dependent, and none of the answers address that.
– Thomas Dickey
Oct 19 '16 at 1:11




It's terminal dependent, and none of the answers address that.
– Thomas Dickey
Oct 19 '16 at 1:11










9 Answers
9






active

oldest

votes

















up vote
68
down vote



accepted










You can use tput reset.



Besides reset and tput reset you can use following shell script.



#!/bin/sh
echo -e \033c


This sends control characters Esc-C to the console which resets the terminal.



Google Keywords: Linux Console Control Sequences



man console_codes says:




The sequence ESC c causes a terminal reset, which is what you want if
the screen is all garbled. The oft-advised "echo ^V^O" will only make
G0 current, but there is no guarantee that G0 points at table a). In
some distributions there is a program reset(1) that just does "echo
^[c". If your terminfo entry for the console is correct (and has an
entry rs1=Ec), then "tput reset" will also work.







share|improve this answer


















  • 1




    What's the difference between reset and tput reset?
    – Toothrot
    Oct 18 '16 at 12:19










  • tput reset is faster than reset in Ubuntu 16.04, at least
    – Iván Rodríguez Torres
    Feb 13 '17 at 11:22






  • 5




    -1, you can still see the buffer if you scroll up
    – João Pimentel Ferreira
    Jun 18 '17 at 10:31

















up vote
15
down vote













You can use the reset command, that will reset the terminal settings.






share|improve this answer



























    up vote
    15
    down vote













    I know you're on a gnome terminal, but I thought I'd answer with a tip for others who might be (like me) on a Mac:



    If you're using Terminal.app or iTerm.app then Control+L will scroll up so the terminal looks blank, but Cmd+K will actually reset the terminal / clear scroll-back.



    Or, if you're able to set keyboard preferences for your terminal you may be able to assign something like Ctrl+K to input echo -e \033c as was mentioned above.






    share|improve this answer
















    • 2




      Cmd+K is all i wanted. ty
      – Gaurav Gandhi
      Mar 30 '16 at 11:13

















    up vote
    8
    down vote













    Anthon's answer works in KDE Konsole, but not urxvt. In urxvt, I've been using reset for a few years to clear the scrollback (along with all the other things it does), and wasn't satisfied that it didn't work in Konsole. So now for Linux I have a new alias:



    alias allclear='clear; echo -e "33ce[3J"'


    But it doesn't work on OS X.



    tput reset doesn't work in any context AFAICT.



    In KDE Konsole, ctrl-shift-k clears the scrollback (including the current shell prompt, so it's completely empty). In iTerm or Apple's terminal on OS X, cmd-shift-k also clears scrollback. To add this feature to urxvt, add this to ~/.Xresources:



    urxvt*keysym.C-S-K: command:33c





    share|improve this answer






















    • This answer is the answer that anybody using Linux Bash will love if they are expecting the same result as they would receive on a Mac by pressing command + K. I went ahead and turned this into a standalone command by adding the following function to the bottom of /etc/bash.bashrc (then log out of server, log back in and it will work via the command allclear): allclear() ` echo "Clearing terminal and scrollback..."` ` sleep 1.5` ` clear; echo -e "33ce[3J"` ` Edit: Can't get formatting to work. If anybody is able to edit this so it is readable, I would appreciate it.
      – KLaw
      Feb 7 at 16:26


















    up vote
    3
    down vote













    I found this on the net years ago, and works well for me. It completely clears the terminal with no scroll history.



    echo -e "e[3J"





    share|improve this answer





























      up vote
      2
      down vote













      I mapped F12 to clear screen in each of the following shells: bash, csh and fish shell.
      My command is different from all previous ones because it preserves whatever you've already typed in the current line.
      (Note: all the configurations below are terminal dependent, but I hope they will work virtually everywhere)



      bash



      Open the file ~/.inputrc and insert the following line:



      "e[24~": "C-k C-uecho -ne '\ec\e[3J'; history -d $((HISTCMD-1))nC-yC-?"



      To have the new key binding available, either open a new terminal or type Ctrl+X then Ctrl+R to reload the .inputrc file in the current terminal.



      Explanation

      The file ~/.inputrc controls the key bindings of the bash terminal.



      About the line:



      1. The first part of the line, "e[24~", maps the key F12.

      2. The C-k (Ctrl+X) clears the kill-ring (bash's copy-and-past memory).

      3. The space avoids a beep in the next command.

      4. The C-u (Ctrl+U) sends the current line to the kill-ring, and erase it.

      5. The echo -ne '\ec\e[3J'; history -d $((HISTCMD-1))n sends two grouped commands to the terminal. They are separated by ; and terminated by n.

        • The echo -ne '\ec\e[3J' clears the screen.

        • The history -d $((HISTCMD-1)) avoids these two commands from entering in history.


      6. The C-y (Ctrl+Y) pastes the kill-ring stored by the C-u command.

      7. The C-? (Ctrl+?) is equivalent to Backspace and removes the space inserted in step 3 above.

      References:



      • How to bind a function key to a command in bash (and how to prevent Ctrl+U from ringing):
        https://stackoverflow.com/a/4201274/1669975

      • How to reload the .inputrc file: https://superuser.com/a/241190/595358

      • How to execute a command without keeping it in history: https://stackoverflow.com/a/33511637/1669975

      csh



      Type the command bellow.
      bindkey -c "^[[24~" "echo -ne 'ece[3J'"

      It can also be inserted in your .cshrc file to load the key binding to every new terminal.
      (Yes, it is much simpler than in bash)



      fish shell



      Type the command bellow.
      bind -k f12 "echo -ne 'ece[3J'; commandline -f repaint"

      You can edit and save the function fish_user_key_bindings to load the key binding to every new terminal.
      (Yes, it is much simpler than in bash)






      share|improve this answer





























        up vote
        1
        down vote













        For me, using PuTTY against CentOS 7, clear leaves only the clear command in the scrollback, but running "clear && clear", two instances of the clear command at the same time, completely clears the scrollback and leaves me with no scrollbar. Try that. It's a weird solution but none of these here cleared the scrollback that effectively, and this does.






        share|improve this answer



























          up vote
          1
          down vote













          [Ubuntu 16.04]



          The .bash_history file is created in the user's home directory once the terminal is closed



          It is useful, but you could delete it if you wish.. Nevertheless it would be created every time you finish using the terminal.



          You could delete it manually from:



          • your files browser.


          • the terminal: remember that a new .bash_history file will be created when you close the terminal (based in its default configuration).


          Or you can call a custom function if you save the functionality you need into a file linked from the bashrc.. you could edit the bashrc itself if you like putting your code there, but the next examples are in a separate file



          Honestly this is not useful for me but if you wish is to delete the commands history before exit you could do this:


          .bash_custom #this is my custom file



          blotout() 
          HISTSIZE=0
          rm $HOME/.bash_history
          exit



          then at the bottom of add the name and path of my file

          .bashrc # this is the configuration file for the bash (I think)



          # existent code
          #...
          #..

          # import user customizations
          source $HOME/.bash_custom


          and thatś all.



          BUT, to do exactly what you want you just need this function in your custom file and link it:



          refresh() 
          tput reset
          H=HISTSIZE
          HISTSIZE=0
          HISTSIZE=H



          Or just put the function in the .bashrc if you want but that way you probably need an export statement after the function I'm not sure and if the file is updated probably lost your functions.. I'm not sure about that too :D .

          Remember you have to re-start the terminal when edit the .bashrc or your 'custom' file.






          share|improve this answer



























            up vote
            0
            down vote













            Added to ~/.inputrc to bind the complete clearing to F12:



            "e[24~":'!echo -ne 47\0033\014347r'





            share|improve this answer




















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "106"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f26975%2fhow-do-i-clear-the-gnome-terminal-history%23new-answer', 'question_page');

              );

              Post as a guest






























              9 Answers
              9






              active

              oldest

              votes








              9 Answers
              9






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              68
              down vote



              accepted










              You can use tput reset.



              Besides reset and tput reset you can use following shell script.



              #!/bin/sh
              echo -e \033c


              This sends control characters Esc-C to the console which resets the terminal.



              Google Keywords: Linux Console Control Sequences



              man console_codes says:




              The sequence ESC c causes a terminal reset, which is what you want if
              the screen is all garbled. The oft-advised "echo ^V^O" will only make
              G0 current, but there is no guarantee that G0 points at table a). In
              some distributions there is a program reset(1) that just does "echo
              ^[c". If your terminfo entry for the console is correct (and has an
              entry rs1=Ec), then "tput reset" will also work.







              share|improve this answer


















              • 1




                What's the difference between reset and tput reset?
                – Toothrot
                Oct 18 '16 at 12:19










              • tput reset is faster than reset in Ubuntu 16.04, at least
                – Iván Rodríguez Torres
                Feb 13 '17 at 11:22






              • 5




                -1, you can still see the buffer if you scroll up
                – João Pimentel Ferreira
                Jun 18 '17 at 10:31














              up vote
              68
              down vote



              accepted










              You can use tput reset.



              Besides reset and tput reset you can use following shell script.



              #!/bin/sh
              echo -e \033c


              This sends control characters Esc-C to the console which resets the terminal.



              Google Keywords: Linux Console Control Sequences



              man console_codes says:




              The sequence ESC c causes a terminal reset, which is what you want if
              the screen is all garbled. The oft-advised "echo ^V^O" will only make
              G0 current, but there is no guarantee that G0 points at table a). In
              some distributions there is a program reset(1) that just does "echo
              ^[c". If your terminfo entry for the console is correct (and has an
              entry rs1=Ec), then "tput reset" will also work.







              share|improve this answer


















              • 1




                What's the difference between reset and tput reset?
                – Toothrot
                Oct 18 '16 at 12:19










              • tput reset is faster than reset in Ubuntu 16.04, at least
                – Iván Rodríguez Torres
                Feb 13 '17 at 11:22






              • 5




                -1, you can still see the buffer if you scroll up
                – João Pimentel Ferreira
                Jun 18 '17 at 10:31












              up vote
              68
              down vote



              accepted







              up vote
              68
              down vote



              accepted






              You can use tput reset.



              Besides reset and tput reset you can use following shell script.



              #!/bin/sh
              echo -e \033c


              This sends control characters Esc-C to the console which resets the terminal.



              Google Keywords: Linux Console Control Sequences



              man console_codes says:




              The sequence ESC c causes a terminal reset, which is what you want if
              the screen is all garbled. The oft-advised "echo ^V^O" will only make
              G0 current, but there is no guarantee that G0 points at table a). In
              some distributions there is a program reset(1) that just does "echo
              ^[c". If your terminfo entry for the console is correct (and has an
              entry rs1=Ec), then "tput reset" will also work.







              share|improve this answer














              You can use tput reset.



              Besides reset and tput reset you can use following shell script.



              #!/bin/sh
              echo -e \033c


              This sends control characters Esc-C to the console which resets the terminal.



              Google Keywords: Linux Console Control Sequences



              man console_codes says:




              The sequence ESC c causes a terminal reset, which is what you want if
              the screen is all garbled. The oft-advised "echo ^V^O" will only make
              G0 current, but there is no guarantee that G0 points at table a). In
              some distributions there is a program reset(1) that just does "echo
              ^[c". If your terminfo entry for the console is correct (and has an
              entry rs1=Ec), then "tput reset" will also work.








              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Dec 16 '11 at 14:23

























              answered Dec 16 '11 at 13:55









              Sachin Divekar

              3,7381619




              3,7381619







              • 1




                What's the difference between reset and tput reset?
                – Toothrot
                Oct 18 '16 at 12:19










              • tput reset is faster than reset in Ubuntu 16.04, at least
                – Iván Rodríguez Torres
                Feb 13 '17 at 11:22






              • 5




                -1, you can still see the buffer if you scroll up
                – João Pimentel Ferreira
                Jun 18 '17 at 10:31












              • 1




                What's the difference between reset and tput reset?
                – Toothrot
                Oct 18 '16 at 12:19










              • tput reset is faster than reset in Ubuntu 16.04, at least
                – Iván Rodríguez Torres
                Feb 13 '17 at 11:22






              • 5




                -1, you can still see the buffer if you scroll up
                – João Pimentel Ferreira
                Jun 18 '17 at 10:31







              1




              1




              What's the difference between reset and tput reset?
              – Toothrot
              Oct 18 '16 at 12:19




              What's the difference between reset and tput reset?
              – Toothrot
              Oct 18 '16 at 12:19












              tput reset is faster than reset in Ubuntu 16.04, at least
              – Iván Rodríguez Torres
              Feb 13 '17 at 11:22




              tput reset is faster than reset in Ubuntu 16.04, at least
              – Iván Rodríguez Torres
              Feb 13 '17 at 11:22




              5




              5




              -1, you can still see the buffer if you scroll up
              – João Pimentel Ferreira
              Jun 18 '17 at 10:31




              -1, you can still see the buffer if you scroll up
              – João Pimentel Ferreira
              Jun 18 '17 at 10:31












              up vote
              15
              down vote













              You can use the reset command, that will reset the terminal settings.






              share|improve this answer
























                up vote
                15
                down vote













                You can use the reset command, that will reset the terminal settings.






                share|improve this answer






















                  up vote
                  15
                  down vote










                  up vote
                  15
                  down vote









                  You can use the reset command, that will reset the terminal settings.






                  share|improve this answer












                  You can use the reset command, that will reset the terminal settings.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 16 '11 at 13:33









                  enzotib

                  32.5k710292




                  32.5k710292




















                      up vote
                      15
                      down vote













                      I know you're on a gnome terminal, but I thought I'd answer with a tip for others who might be (like me) on a Mac:



                      If you're using Terminal.app or iTerm.app then Control+L will scroll up so the terminal looks blank, but Cmd+K will actually reset the terminal / clear scroll-back.



                      Or, if you're able to set keyboard preferences for your terminal you may be able to assign something like Ctrl+K to input echo -e \033c as was mentioned above.






                      share|improve this answer
















                      • 2




                        Cmd+K is all i wanted. ty
                        – Gaurav Gandhi
                        Mar 30 '16 at 11:13














                      up vote
                      15
                      down vote













                      I know you're on a gnome terminal, but I thought I'd answer with a tip for others who might be (like me) on a Mac:



                      If you're using Terminal.app or iTerm.app then Control+L will scroll up so the terminal looks blank, but Cmd+K will actually reset the terminal / clear scroll-back.



                      Or, if you're able to set keyboard preferences for your terminal you may be able to assign something like Ctrl+K to input echo -e \033c as was mentioned above.






                      share|improve this answer
















                      • 2




                        Cmd+K is all i wanted. ty
                        – Gaurav Gandhi
                        Mar 30 '16 at 11:13












                      up vote
                      15
                      down vote










                      up vote
                      15
                      down vote









                      I know you're on a gnome terminal, but I thought I'd answer with a tip for others who might be (like me) on a Mac:



                      If you're using Terminal.app or iTerm.app then Control+L will scroll up so the terminal looks blank, but Cmd+K will actually reset the terminal / clear scroll-back.



                      Or, if you're able to set keyboard preferences for your terminal you may be able to assign something like Ctrl+K to input echo -e \033c as was mentioned above.






                      share|improve this answer












                      I know you're on a gnome terminal, but I thought I'd answer with a tip for others who might be (like me) on a Mac:



                      If you're using Terminal.app or iTerm.app then Control+L will scroll up so the terminal looks blank, but Cmd+K will actually reset the terminal / clear scroll-back.



                      Or, if you're able to set keyboard preferences for your terminal you may be able to assign something like Ctrl+K to input echo -e \033c as was mentioned above.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jan 7 '12 at 17:22









                      cwd

                      12.8k52114155




                      12.8k52114155







                      • 2




                        Cmd+K is all i wanted. ty
                        – Gaurav Gandhi
                        Mar 30 '16 at 11:13












                      • 2




                        Cmd+K is all i wanted. ty
                        – Gaurav Gandhi
                        Mar 30 '16 at 11:13







                      2




                      2




                      Cmd+K is all i wanted. ty
                      – Gaurav Gandhi
                      Mar 30 '16 at 11:13




                      Cmd+K is all i wanted. ty
                      – Gaurav Gandhi
                      Mar 30 '16 at 11:13










                      up vote
                      8
                      down vote













                      Anthon's answer works in KDE Konsole, but not urxvt. In urxvt, I've been using reset for a few years to clear the scrollback (along with all the other things it does), and wasn't satisfied that it didn't work in Konsole. So now for Linux I have a new alias:



                      alias allclear='clear; echo -e "33ce[3J"'


                      But it doesn't work on OS X.



                      tput reset doesn't work in any context AFAICT.



                      In KDE Konsole, ctrl-shift-k clears the scrollback (including the current shell prompt, so it's completely empty). In iTerm or Apple's terminal on OS X, cmd-shift-k also clears scrollback. To add this feature to urxvt, add this to ~/.Xresources:



                      urxvt*keysym.C-S-K: command:33c





                      share|improve this answer






















                      • This answer is the answer that anybody using Linux Bash will love if they are expecting the same result as they would receive on a Mac by pressing command + K. I went ahead and turned this into a standalone command by adding the following function to the bottom of /etc/bash.bashrc (then log out of server, log back in and it will work via the command allclear): allclear() ` echo "Clearing terminal and scrollback..."` ` sleep 1.5` ` clear; echo -e "33ce[3J"` ` Edit: Can't get formatting to work. If anybody is able to edit this so it is readable, I would appreciate it.
                        – KLaw
                        Feb 7 at 16:26















                      up vote
                      8
                      down vote













                      Anthon's answer works in KDE Konsole, but not urxvt. In urxvt, I've been using reset for a few years to clear the scrollback (along with all the other things it does), and wasn't satisfied that it didn't work in Konsole. So now for Linux I have a new alias:



                      alias allclear='clear; echo -e "33ce[3J"'


                      But it doesn't work on OS X.



                      tput reset doesn't work in any context AFAICT.



                      In KDE Konsole, ctrl-shift-k clears the scrollback (including the current shell prompt, so it's completely empty). In iTerm or Apple's terminal on OS X, cmd-shift-k also clears scrollback. To add this feature to urxvt, add this to ~/.Xresources:



                      urxvt*keysym.C-S-K: command:33c





                      share|improve this answer






















                      • This answer is the answer that anybody using Linux Bash will love if they are expecting the same result as they would receive on a Mac by pressing command + K. I went ahead and turned this into a standalone command by adding the following function to the bottom of /etc/bash.bashrc (then log out of server, log back in and it will work via the command allclear): allclear() ` echo "Clearing terminal and scrollback..."` ` sleep 1.5` ` clear; echo -e "33ce[3J"` ` Edit: Can't get formatting to work. If anybody is able to edit this so it is readable, I would appreciate it.
                        – KLaw
                        Feb 7 at 16:26













                      up vote
                      8
                      down vote










                      up vote
                      8
                      down vote









                      Anthon's answer works in KDE Konsole, but not urxvt. In urxvt, I've been using reset for a few years to clear the scrollback (along with all the other things it does), and wasn't satisfied that it didn't work in Konsole. So now for Linux I have a new alias:



                      alias allclear='clear; echo -e "33ce[3J"'


                      But it doesn't work on OS X.



                      tput reset doesn't work in any context AFAICT.



                      In KDE Konsole, ctrl-shift-k clears the scrollback (including the current shell prompt, so it's completely empty). In iTerm or Apple's terminal on OS X, cmd-shift-k also clears scrollback. To add this feature to urxvt, add this to ~/.Xresources:



                      urxvt*keysym.C-S-K: command:33c





                      share|improve this answer














                      Anthon's answer works in KDE Konsole, but not urxvt. In urxvt, I've been using reset for a few years to clear the scrollback (along with all the other things it does), and wasn't satisfied that it didn't work in Konsole. So now for Linux I have a new alias:



                      alias allclear='clear; echo -e "33ce[3J"'


                      But it doesn't work on OS X.



                      tput reset doesn't work in any context AFAICT.



                      In KDE Konsole, ctrl-shift-k clears the scrollback (including the current shell prompt, so it's completely empty). In iTerm or Apple's terminal on OS X, cmd-shift-k also clears scrollback. To add this feature to urxvt, add this to ~/.Xresources:



                      urxvt*keysym.C-S-K: command:33c






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Mar 13 '15 at 12:00

























                      answered Mar 13 '15 at 10:40









                      ecloud

                      8112




                      8112











                      • This answer is the answer that anybody using Linux Bash will love if they are expecting the same result as they would receive on a Mac by pressing command + K. I went ahead and turned this into a standalone command by adding the following function to the bottom of /etc/bash.bashrc (then log out of server, log back in and it will work via the command allclear): allclear() ` echo "Clearing terminal and scrollback..."` ` sleep 1.5` ` clear; echo -e "33ce[3J"` ` Edit: Can't get formatting to work. If anybody is able to edit this so it is readable, I would appreciate it.
                        – KLaw
                        Feb 7 at 16:26

















                      • This answer is the answer that anybody using Linux Bash will love if they are expecting the same result as they would receive on a Mac by pressing command + K. I went ahead and turned this into a standalone command by adding the following function to the bottom of /etc/bash.bashrc (then log out of server, log back in and it will work via the command allclear): allclear() ` echo "Clearing terminal and scrollback..."` ` sleep 1.5` ` clear; echo -e "33ce[3J"` ` Edit: Can't get formatting to work. If anybody is able to edit this so it is readable, I would appreciate it.
                        – KLaw
                        Feb 7 at 16:26
















                      This answer is the answer that anybody using Linux Bash will love if they are expecting the same result as they would receive on a Mac by pressing command + K. I went ahead and turned this into a standalone command by adding the following function to the bottom of /etc/bash.bashrc (then log out of server, log back in and it will work via the command allclear): allclear() ` echo "Clearing terminal and scrollback..."` ` sleep 1.5` ` clear; echo -e "33ce[3J"` ` Edit: Can't get formatting to work. If anybody is able to edit this so it is readable, I would appreciate it.
                      – KLaw
                      Feb 7 at 16:26





                      This answer is the answer that anybody using Linux Bash will love if they are expecting the same result as they would receive on a Mac by pressing command + K. I went ahead and turned this into a standalone command by adding the following function to the bottom of /etc/bash.bashrc (then log out of server, log back in and it will work via the command allclear): allclear() ` echo "Clearing terminal and scrollback..."` ` sleep 1.5` ` clear; echo -e "33ce[3J"` ` Edit: Can't get formatting to work. If anybody is able to edit this so it is readable, I would appreciate it.
                      – KLaw
                      Feb 7 at 16:26











                      up vote
                      3
                      down vote













                      I found this on the net years ago, and works well for me. It completely clears the terminal with no scroll history.



                      echo -e "e[3J"





                      share|improve this answer


























                        up vote
                        3
                        down vote













                        I found this on the net years ago, and works well for me. It completely clears the terminal with no scroll history.



                        echo -e "e[3J"





                        share|improve this answer
























                          up vote
                          3
                          down vote










                          up vote
                          3
                          down vote









                          I found this on the net years ago, and works well for me. It completely clears the terminal with no scroll history.



                          echo -e "e[3J"





                          share|improve this answer














                          I found this on the net years ago, and works well for me. It completely clears the terminal with no scroll history.



                          echo -e "e[3J"






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Feb 25 '14 at 13:21









                          Anthon

                          58.9k1796160




                          58.9k1796160










                          answered Feb 25 '14 at 13:03









                          canon

                          4913




                          4913




















                              up vote
                              2
                              down vote













                              I mapped F12 to clear screen in each of the following shells: bash, csh and fish shell.
                              My command is different from all previous ones because it preserves whatever you've already typed in the current line.
                              (Note: all the configurations below are terminal dependent, but I hope they will work virtually everywhere)



                              bash



                              Open the file ~/.inputrc and insert the following line:



                              "e[24~": "C-k C-uecho -ne '\ec\e[3J'; history -d $((HISTCMD-1))nC-yC-?"



                              To have the new key binding available, either open a new terminal or type Ctrl+X then Ctrl+R to reload the .inputrc file in the current terminal.



                              Explanation

                              The file ~/.inputrc controls the key bindings of the bash terminal.



                              About the line:



                              1. The first part of the line, "e[24~", maps the key F12.

                              2. The C-k (Ctrl+X) clears the kill-ring (bash's copy-and-past memory).

                              3. The space avoids a beep in the next command.

                              4. The C-u (Ctrl+U) sends the current line to the kill-ring, and erase it.

                              5. The echo -ne '\ec\e[3J'; history -d $((HISTCMD-1))n sends two grouped commands to the terminal. They are separated by ; and terminated by n.

                                • The echo -ne '\ec\e[3J' clears the screen.

                                • The history -d $((HISTCMD-1)) avoids these two commands from entering in history.


                              6. The C-y (Ctrl+Y) pastes the kill-ring stored by the C-u command.

                              7. The C-? (Ctrl+?) is equivalent to Backspace and removes the space inserted in step 3 above.

                              References:



                              • How to bind a function key to a command in bash (and how to prevent Ctrl+U from ringing):
                                https://stackoverflow.com/a/4201274/1669975

                              • How to reload the .inputrc file: https://superuser.com/a/241190/595358

                              • How to execute a command without keeping it in history: https://stackoverflow.com/a/33511637/1669975

                              csh



                              Type the command bellow.
                              bindkey -c "^[[24~" "echo -ne 'ece[3J'"

                              It can also be inserted in your .cshrc file to load the key binding to every new terminal.
                              (Yes, it is much simpler than in bash)



                              fish shell



                              Type the command bellow.
                              bind -k f12 "echo -ne 'ece[3J'; commandline -f repaint"

                              You can edit and save the function fish_user_key_bindings to load the key binding to every new terminal.
                              (Yes, it is much simpler than in bash)






                              share|improve this answer


























                                up vote
                                2
                                down vote













                                I mapped F12 to clear screen in each of the following shells: bash, csh and fish shell.
                                My command is different from all previous ones because it preserves whatever you've already typed in the current line.
                                (Note: all the configurations below are terminal dependent, but I hope they will work virtually everywhere)



                                bash



                                Open the file ~/.inputrc and insert the following line:



                                "e[24~": "C-k C-uecho -ne '\ec\e[3J'; history -d $((HISTCMD-1))nC-yC-?"



                                To have the new key binding available, either open a new terminal or type Ctrl+X then Ctrl+R to reload the .inputrc file in the current terminal.



                                Explanation

                                The file ~/.inputrc controls the key bindings of the bash terminal.



                                About the line:



                                1. The first part of the line, "e[24~", maps the key F12.

                                2. The C-k (Ctrl+X) clears the kill-ring (bash's copy-and-past memory).

                                3. The space avoids a beep in the next command.

                                4. The C-u (Ctrl+U) sends the current line to the kill-ring, and erase it.

                                5. The echo -ne '\ec\e[3J'; history -d $((HISTCMD-1))n sends two grouped commands to the terminal. They are separated by ; and terminated by n.

                                  • The echo -ne '\ec\e[3J' clears the screen.

                                  • The history -d $((HISTCMD-1)) avoids these two commands from entering in history.


                                6. The C-y (Ctrl+Y) pastes the kill-ring stored by the C-u command.

                                7. The C-? (Ctrl+?) is equivalent to Backspace and removes the space inserted in step 3 above.

                                References:



                                • How to bind a function key to a command in bash (and how to prevent Ctrl+U from ringing):
                                  https://stackoverflow.com/a/4201274/1669975

                                • How to reload the .inputrc file: https://superuser.com/a/241190/595358

                                • How to execute a command without keeping it in history: https://stackoverflow.com/a/33511637/1669975

                                csh



                                Type the command bellow.
                                bindkey -c "^[[24~" "echo -ne 'ece[3J'"

                                It can also be inserted in your .cshrc file to load the key binding to every new terminal.
                                (Yes, it is much simpler than in bash)



                                fish shell



                                Type the command bellow.
                                bind -k f12 "echo -ne 'ece[3J'; commandline -f repaint"

                                You can edit and save the function fish_user_key_bindings to load the key binding to every new terminal.
                                (Yes, it is much simpler than in bash)






                                share|improve this answer
























                                  up vote
                                  2
                                  down vote










                                  up vote
                                  2
                                  down vote









                                  I mapped F12 to clear screen in each of the following shells: bash, csh and fish shell.
                                  My command is different from all previous ones because it preserves whatever you've already typed in the current line.
                                  (Note: all the configurations below are terminal dependent, but I hope they will work virtually everywhere)



                                  bash



                                  Open the file ~/.inputrc and insert the following line:



                                  "e[24~": "C-k C-uecho -ne '\ec\e[3J'; history -d $((HISTCMD-1))nC-yC-?"



                                  To have the new key binding available, either open a new terminal or type Ctrl+X then Ctrl+R to reload the .inputrc file in the current terminal.



                                  Explanation

                                  The file ~/.inputrc controls the key bindings of the bash terminal.



                                  About the line:



                                  1. The first part of the line, "e[24~", maps the key F12.

                                  2. The C-k (Ctrl+X) clears the kill-ring (bash's copy-and-past memory).

                                  3. The space avoids a beep in the next command.

                                  4. The C-u (Ctrl+U) sends the current line to the kill-ring, and erase it.

                                  5. The echo -ne '\ec\e[3J'; history -d $((HISTCMD-1))n sends two grouped commands to the terminal. They are separated by ; and terminated by n.

                                    • The echo -ne '\ec\e[3J' clears the screen.

                                    • The history -d $((HISTCMD-1)) avoids these two commands from entering in history.


                                  6. The C-y (Ctrl+Y) pastes the kill-ring stored by the C-u command.

                                  7. The C-? (Ctrl+?) is equivalent to Backspace and removes the space inserted in step 3 above.

                                  References:



                                  • How to bind a function key to a command in bash (and how to prevent Ctrl+U from ringing):
                                    https://stackoverflow.com/a/4201274/1669975

                                  • How to reload the .inputrc file: https://superuser.com/a/241190/595358

                                  • How to execute a command without keeping it in history: https://stackoverflow.com/a/33511637/1669975

                                  csh



                                  Type the command bellow.
                                  bindkey -c "^[[24~" "echo -ne 'ece[3J'"

                                  It can also be inserted in your .cshrc file to load the key binding to every new terminal.
                                  (Yes, it is much simpler than in bash)



                                  fish shell



                                  Type the command bellow.
                                  bind -k f12 "echo -ne 'ece[3J'; commandline -f repaint"

                                  You can edit and save the function fish_user_key_bindings to load the key binding to every new terminal.
                                  (Yes, it is much simpler than in bash)






                                  share|improve this answer














                                  I mapped F12 to clear screen in each of the following shells: bash, csh and fish shell.
                                  My command is different from all previous ones because it preserves whatever you've already typed in the current line.
                                  (Note: all the configurations below are terminal dependent, but I hope they will work virtually everywhere)



                                  bash



                                  Open the file ~/.inputrc and insert the following line:



                                  "e[24~": "C-k C-uecho -ne '\ec\e[3J'; history -d $((HISTCMD-1))nC-yC-?"



                                  To have the new key binding available, either open a new terminal or type Ctrl+X then Ctrl+R to reload the .inputrc file in the current terminal.



                                  Explanation

                                  The file ~/.inputrc controls the key bindings of the bash terminal.



                                  About the line:



                                  1. The first part of the line, "e[24~", maps the key F12.

                                  2. The C-k (Ctrl+X) clears the kill-ring (bash's copy-and-past memory).

                                  3. The space avoids a beep in the next command.

                                  4. The C-u (Ctrl+U) sends the current line to the kill-ring, and erase it.

                                  5. The echo -ne '\ec\e[3J'; history -d $((HISTCMD-1))n sends two grouped commands to the terminal. They are separated by ; and terminated by n.

                                    • The echo -ne '\ec\e[3J' clears the screen.

                                    • The history -d $((HISTCMD-1)) avoids these two commands from entering in history.


                                  6. The C-y (Ctrl+Y) pastes the kill-ring stored by the C-u command.

                                  7. The C-? (Ctrl+?) is equivalent to Backspace and removes the space inserted in step 3 above.

                                  References:



                                  • How to bind a function key to a command in bash (and how to prevent Ctrl+U from ringing):
                                    https://stackoverflow.com/a/4201274/1669975

                                  • How to reload the .inputrc file: https://superuser.com/a/241190/595358

                                  • How to execute a command without keeping it in history: https://stackoverflow.com/a/33511637/1669975

                                  csh



                                  Type the command bellow.
                                  bindkey -c "^[[24~" "echo -ne 'ece[3J'"

                                  It can also be inserted in your .cshrc file to load the key binding to every new terminal.
                                  (Yes, it is much simpler than in bash)



                                  fish shell



                                  Type the command bellow.
                                  bind -k f12 "echo -ne 'ece[3J'; commandline -f repaint"

                                  You can edit and save the function fish_user_key_bindings to load the key binding to every new terminal.
                                  (Yes, it is much simpler than in bash)







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Jun 12 '17 at 16:04

























                                  answered Jun 12 '17 at 14:23









                                  Akira Cleber Nakandakare

                                  214




                                  214




















                                      up vote
                                      1
                                      down vote













                                      For me, using PuTTY against CentOS 7, clear leaves only the clear command in the scrollback, but running "clear && clear", two instances of the clear command at the same time, completely clears the scrollback and leaves me with no scrollbar. Try that. It's a weird solution but none of these here cleared the scrollback that effectively, and this does.






                                      share|improve this answer
























                                        up vote
                                        1
                                        down vote













                                        For me, using PuTTY against CentOS 7, clear leaves only the clear command in the scrollback, but running "clear && clear", two instances of the clear command at the same time, completely clears the scrollback and leaves me with no scrollbar. Try that. It's a weird solution but none of these here cleared the scrollback that effectively, and this does.






                                        share|improve this answer






















                                          up vote
                                          1
                                          down vote










                                          up vote
                                          1
                                          down vote









                                          For me, using PuTTY against CentOS 7, clear leaves only the clear command in the scrollback, but running "clear && clear", two instances of the clear command at the same time, completely clears the scrollback and leaves me with no scrollbar. Try that. It's a weird solution but none of these here cleared the scrollback that effectively, and this does.






                                          share|improve this answer












                                          For me, using PuTTY against CentOS 7, clear leaves only the clear command in the scrollback, but running "clear && clear", two instances of the clear command at the same time, completely clears the scrollback and leaves me with no scrollbar. Try that. It's a weird solution but none of these here cleared the scrollback that effectively, and this does.







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered May 22 '17 at 20:19









                                          Zoltan Shapiro

                                          111




                                          111




















                                              up vote
                                              1
                                              down vote













                                              [Ubuntu 16.04]



                                              The .bash_history file is created in the user's home directory once the terminal is closed



                                              It is useful, but you could delete it if you wish.. Nevertheless it would be created every time you finish using the terminal.



                                              You could delete it manually from:



                                              • your files browser.


                                              • the terminal: remember that a new .bash_history file will be created when you close the terminal (based in its default configuration).


                                              Or you can call a custom function if you save the functionality you need into a file linked from the bashrc.. you could edit the bashrc itself if you like putting your code there, but the next examples are in a separate file



                                              Honestly this is not useful for me but if you wish is to delete the commands history before exit you could do this:


                                              .bash_custom #this is my custom file



                                              blotout() 
                                              HISTSIZE=0
                                              rm $HOME/.bash_history
                                              exit



                                              then at the bottom of add the name and path of my file

                                              .bashrc # this is the configuration file for the bash (I think)



                                              # existent code
                                              #...
                                              #..

                                              # import user customizations
                                              source $HOME/.bash_custom


                                              and thatś all.



                                              BUT, to do exactly what you want you just need this function in your custom file and link it:



                                              refresh() 
                                              tput reset
                                              H=HISTSIZE
                                              HISTSIZE=0
                                              HISTSIZE=H



                                              Or just put the function in the .bashrc if you want but that way you probably need an export statement after the function I'm not sure and if the file is updated probably lost your functions.. I'm not sure about that too :D .

                                              Remember you have to re-start the terminal when edit the .bashrc or your 'custom' file.






                                              share|improve this answer
























                                                up vote
                                                1
                                                down vote













                                                [Ubuntu 16.04]



                                                The .bash_history file is created in the user's home directory once the terminal is closed



                                                It is useful, but you could delete it if you wish.. Nevertheless it would be created every time you finish using the terminal.



                                                You could delete it manually from:



                                                • your files browser.


                                                • the terminal: remember that a new .bash_history file will be created when you close the terminal (based in its default configuration).


                                                Or you can call a custom function if you save the functionality you need into a file linked from the bashrc.. you could edit the bashrc itself if you like putting your code there, but the next examples are in a separate file



                                                Honestly this is not useful for me but if you wish is to delete the commands history before exit you could do this:


                                                .bash_custom #this is my custom file



                                                blotout() 
                                                HISTSIZE=0
                                                rm $HOME/.bash_history
                                                exit



                                                then at the bottom of add the name and path of my file

                                                .bashrc # this is the configuration file for the bash (I think)



                                                # existent code
                                                #...
                                                #..

                                                # import user customizations
                                                source $HOME/.bash_custom


                                                and thatś all.



                                                BUT, to do exactly what you want you just need this function in your custom file and link it:



                                                refresh() 
                                                tput reset
                                                H=HISTSIZE
                                                HISTSIZE=0
                                                HISTSIZE=H



                                                Or just put the function in the .bashrc if you want but that way you probably need an export statement after the function I'm not sure and if the file is updated probably lost your functions.. I'm not sure about that too :D .

                                                Remember you have to re-start the terminal when edit the .bashrc or your 'custom' file.






                                                share|improve this answer






















                                                  up vote
                                                  1
                                                  down vote










                                                  up vote
                                                  1
                                                  down vote









                                                  [Ubuntu 16.04]



                                                  The .bash_history file is created in the user's home directory once the terminal is closed



                                                  It is useful, but you could delete it if you wish.. Nevertheless it would be created every time you finish using the terminal.



                                                  You could delete it manually from:



                                                  • your files browser.


                                                  • the terminal: remember that a new .bash_history file will be created when you close the terminal (based in its default configuration).


                                                  Or you can call a custom function if you save the functionality you need into a file linked from the bashrc.. you could edit the bashrc itself if you like putting your code there, but the next examples are in a separate file



                                                  Honestly this is not useful for me but if you wish is to delete the commands history before exit you could do this:


                                                  .bash_custom #this is my custom file



                                                  blotout() 
                                                  HISTSIZE=0
                                                  rm $HOME/.bash_history
                                                  exit



                                                  then at the bottom of add the name and path of my file

                                                  .bashrc # this is the configuration file for the bash (I think)



                                                  # existent code
                                                  #...
                                                  #..

                                                  # import user customizations
                                                  source $HOME/.bash_custom


                                                  and thatś all.



                                                  BUT, to do exactly what you want you just need this function in your custom file and link it:



                                                  refresh() 
                                                  tput reset
                                                  H=HISTSIZE
                                                  HISTSIZE=0
                                                  HISTSIZE=H



                                                  Or just put the function in the .bashrc if you want but that way you probably need an export statement after the function I'm not sure and if the file is updated probably lost your functions.. I'm not sure about that too :D .

                                                  Remember you have to re-start the terminal when edit the .bashrc or your 'custom' file.






                                                  share|improve this answer












                                                  [Ubuntu 16.04]



                                                  The .bash_history file is created in the user's home directory once the terminal is closed



                                                  It is useful, but you could delete it if you wish.. Nevertheless it would be created every time you finish using the terminal.



                                                  You could delete it manually from:



                                                  • your files browser.


                                                  • the terminal: remember that a new .bash_history file will be created when you close the terminal (based in its default configuration).


                                                  Or you can call a custom function if you save the functionality you need into a file linked from the bashrc.. you could edit the bashrc itself if you like putting your code there, but the next examples are in a separate file



                                                  Honestly this is not useful for me but if you wish is to delete the commands history before exit you could do this:


                                                  .bash_custom #this is my custom file



                                                  blotout() 
                                                  HISTSIZE=0
                                                  rm $HOME/.bash_history
                                                  exit



                                                  then at the bottom of add the name and path of my file

                                                  .bashrc # this is the configuration file for the bash (I think)



                                                  # existent code
                                                  #...
                                                  #..

                                                  # import user customizations
                                                  source $HOME/.bash_custom


                                                  and thatś all.



                                                  BUT, to do exactly what you want you just need this function in your custom file and link it:



                                                  refresh() 
                                                  tput reset
                                                  H=HISTSIZE
                                                  HISTSIZE=0
                                                  HISTSIZE=H



                                                  Or just put the function in the .bashrc if you want but that way you probably need an export statement after the function I'm not sure and if the file is updated probably lost your functions.. I'm not sure about that too :D .

                                                  Remember you have to re-start the terminal when edit the .bashrc or your 'custom' file.







                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Jun 28 '17 at 22:56









                                                  Federico Gallo

                                                  639




                                                  639




















                                                      up vote
                                                      0
                                                      down vote













                                                      Added to ~/.inputrc to bind the complete clearing to F12:



                                                      "e[24~":'!echo -ne 47\0033\014347r'





                                                      share|improve this answer
























                                                        up vote
                                                        0
                                                        down vote













                                                        Added to ~/.inputrc to bind the complete clearing to F12:



                                                        "e[24~":'!echo -ne 47\0033\014347r'





                                                        share|improve this answer






















                                                          up vote
                                                          0
                                                          down vote










                                                          up vote
                                                          0
                                                          down vote









                                                          Added to ~/.inputrc to bind the complete clearing to F12:



                                                          "e[24~":'!echo -ne 47\0033\014347r'





                                                          share|improve this answer












                                                          Added to ~/.inputrc to bind the complete clearing to F12:



                                                          "e[24~":'!echo -ne 47\0033\014347r'






                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered Oct 18 '16 at 12:03









                                                          Velkan

                                                          231110




                                                          231110



























                                                               

                                                              draft saved


                                                              draft discarded















































                                                               


                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function ()
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f26975%2fhow-do-i-clear-the-gnome-terminal-history%23new-answer', 'question_page');

                                                              );

                                                              Post as a guest













































































                                                              Popular posts from this blog

                                                              How to check contact read email or not when send email to Individual?

                                                              Displaying single band from multi-band raster using QGIS

                                                              How many registers does an x86_64 CPU actually have?