The easiest way to clear scrollback buffer of terminal + some deeper explanation?

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











up vote
2
down vote

favorite












Why bother?



Clearing scrollback buffer is handy in many ways, for example, when I wish to run some command with long output, and want to quickly scroll to start of this output. When scrollback buffer is cleared, I can just scroll to top, and will be done.



Some considerations:



There is clear command, according to man,




clear clears your screen if this is possible, including its scrollback buffer (if the extended "E3" capability is defined).




In gnome-terminal clear does not clear scrollback buffer. (What is "E3" capability, though?)



There is also reset, which clears, but it does a little bit more than that, and it is really slow (on my system it takes more than a second, which is significant delay for humans to be noticed).



And there is echo -ne 'ec' or echo -ne '33c', which does the job. And indeed it is much faster than reset.



The question is, what is ec sequence, how it differs from what clear and reset does, and why there is no separate command for it?



There is also readline's C-l key sequence, which by default bound to clear-screen command (I mean, readline command, not shell command). What is this command? Which escape sequence it emits? How does it actually work? Does it run shell command? Or what? Again, in gnome-terminal, it seems like it works just by spiting out blank lines until prompt appear in top line of terminal. Not sure about other terminal emulators. This is very cumbersome behavior. It pollutes scrollback with chunks of emptiness, so you must scroll up more, and more. It is like a hack, rather than clean solution.



Another question is, is there a readline command for mentioned ec sequence? I want to bound it to C-l instead because I always want to clear scrollback buffer when I clear the screen.



And another question is how to just type such escape sequence into terminal, to perform desired action? Then do not have to think about binding C-l to another readline command (if such command exists). I tried typing Esc, then c but this does not work.



UPDATE
This question answered mostly here: https://unix.stackexchange.com/a/375784/257159. It is very good answer which explains almost all questions asked here.







share|improve this question






















  • Please unlearn the habit of using echo -ne. Use printf instead. There are several systems where echo -ne … will literally print -ne …
    – Fox
    Dec 13 '17 at 18:39






  • 2




    This is, by my count, at least six questions in one, which is not good. There should be one question per question. Moreover, so much of the background to this question would be improved from reading what we already have that covers this, including unix.stackexchange.com/questions/87469 , unix.stackexchange.com/questions/65803 , unix.stackexchange.com/questions/335648 , unix.stackexchange.com/questions/375743 , unix.stackexchange.com/questions/10394 , and unix.stackexchange.com/questions/26975 just for starters.
    – JdeBP
    Dec 13 '17 at 21:02














up vote
2
down vote

favorite












Why bother?



Clearing scrollback buffer is handy in many ways, for example, when I wish to run some command with long output, and want to quickly scroll to start of this output. When scrollback buffer is cleared, I can just scroll to top, and will be done.



Some considerations:



There is clear command, according to man,




clear clears your screen if this is possible, including its scrollback buffer (if the extended "E3" capability is defined).




In gnome-terminal clear does not clear scrollback buffer. (What is "E3" capability, though?)



There is also reset, which clears, but it does a little bit more than that, and it is really slow (on my system it takes more than a second, which is significant delay for humans to be noticed).



And there is echo -ne 'ec' or echo -ne '33c', which does the job. And indeed it is much faster than reset.



The question is, what is ec sequence, how it differs from what clear and reset does, and why there is no separate command for it?



There is also readline's C-l key sequence, which by default bound to clear-screen command (I mean, readline command, not shell command). What is this command? Which escape sequence it emits? How does it actually work? Does it run shell command? Or what? Again, in gnome-terminal, it seems like it works just by spiting out blank lines until prompt appear in top line of terminal. Not sure about other terminal emulators. This is very cumbersome behavior. It pollutes scrollback with chunks of emptiness, so you must scroll up more, and more. It is like a hack, rather than clean solution.



Another question is, is there a readline command for mentioned ec sequence? I want to bound it to C-l instead because I always want to clear scrollback buffer when I clear the screen.



And another question is how to just type such escape sequence into terminal, to perform desired action? Then do not have to think about binding C-l to another readline command (if such command exists). I tried typing Esc, then c but this does not work.



UPDATE
This question answered mostly here: https://unix.stackexchange.com/a/375784/257159. It is very good answer which explains almost all questions asked here.







share|improve this question






















  • Please unlearn the habit of using echo -ne. Use printf instead. There are several systems where echo -ne … will literally print -ne …
    – Fox
    Dec 13 '17 at 18:39






  • 2




    This is, by my count, at least six questions in one, which is not good. There should be one question per question. Moreover, so much of the background to this question would be improved from reading what we already have that covers this, including unix.stackexchange.com/questions/87469 , unix.stackexchange.com/questions/65803 , unix.stackexchange.com/questions/335648 , unix.stackexchange.com/questions/375743 , unix.stackexchange.com/questions/10394 , and unix.stackexchange.com/questions/26975 just for starters.
    – JdeBP
    Dec 13 '17 at 21:02












up vote
2
down vote

favorite









up vote
2
down vote

favorite











Why bother?



Clearing scrollback buffer is handy in many ways, for example, when I wish to run some command with long output, and want to quickly scroll to start of this output. When scrollback buffer is cleared, I can just scroll to top, and will be done.



Some considerations:



There is clear command, according to man,




clear clears your screen if this is possible, including its scrollback buffer (if the extended "E3" capability is defined).




In gnome-terminal clear does not clear scrollback buffer. (What is "E3" capability, though?)



There is also reset, which clears, but it does a little bit more than that, and it is really slow (on my system it takes more than a second, which is significant delay for humans to be noticed).



And there is echo -ne 'ec' or echo -ne '33c', which does the job. And indeed it is much faster than reset.



The question is, what is ec sequence, how it differs from what clear and reset does, and why there is no separate command for it?



There is also readline's C-l key sequence, which by default bound to clear-screen command (I mean, readline command, not shell command). What is this command? Which escape sequence it emits? How does it actually work? Does it run shell command? Or what? Again, in gnome-terminal, it seems like it works just by spiting out blank lines until prompt appear in top line of terminal. Not sure about other terminal emulators. This is very cumbersome behavior. It pollutes scrollback with chunks of emptiness, so you must scroll up more, and more. It is like a hack, rather than clean solution.



Another question is, is there a readline command for mentioned ec sequence? I want to bound it to C-l instead because I always want to clear scrollback buffer when I clear the screen.



And another question is how to just type such escape sequence into terminal, to perform desired action? Then do not have to think about binding C-l to another readline command (if such command exists). I tried typing Esc, then c but this does not work.



UPDATE
This question answered mostly here: https://unix.stackexchange.com/a/375784/257159. It is very good answer which explains almost all questions asked here.







share|improve this question














Why bother?



Clearing scrollback buffer is handy in many ways, for example, when I wish to run some command with long output, and want to quickly scroll to start of this output. When scrollback buffer is cleared, I can just scroll to top, and will be done.



Some considerations:



There is clear command, according to man,




clear clears your screen if this is possible, including its scrollback buffer (if the extended "E3" capability is defined).




In gnome-terminal clear does not clear scrollback buffer. (What is "E3" capability, though?)



There is also reset, which clears, but it does a little bit more than that, and it is really slow (on my system it takes more than a second, which is significant delay for humans to be noticed).



And there is echo -ne 'ec' or echo -ne '33c', which does the job. And indeed it is much faster than reset.



The question is, what is ec sequence, how it differs from what clear and reset does, and why there is no separate command for it?



There is also readline's C-l key sequence, which by default bound to clear-screen command (I mean, readline command, not shell command). What is this command? Which escape sequence it emits? How does it actually work? Does it run shell command? Or what? Again, in gnome-terminal, it seems like it works just by spiting out blank lines until prompt appear in top line of terminal. Not sure about other terminal emulators. This is very cumbersome behavior. It pollutes scrollback with chunks of emptiness, so you must scroll up more, and more. It is like a hack, rather than clean solution.



Another question is, is there a readline command for mentioned ec sequence? I want to bound it to C-l instead because I always want to clear scrollback buffer when I clear the screen.



And another question is how to just type such escape sequence into terminal, to perform desired action? Then do not have to think about binding C-l to another readline command (if such command exists). I tried typing Esc, then c but this does not work.



UPDATE
This question answered mostly here: https://unix.stackexchange.com/a/375784/257159. It is very good answer which explains almost all questions asked here.









share|improve this question













share|improve this question




share|improve this question








edited Dec 14 '17 at 7:18

























asked Dec 13 '17 at 17:52









tosh

1142




1142











  • Please unlearn the habit of using echo -ne. Use printf instead. There are several systems where echo -ne … will literally print -ne …
    – Fox
    Dec 13 '17 at 18:39






  • 2




    This is, by my count, at least six questions in one, which is not good. There should be one question per question. Moreover, so much of the background to this question would be improved from reading what we already have that covers this, including unix.stackexchange.com/questions/87469 , unix.stackexchange.com/questions/65803 , unix.stackexchange.com/questions/335648 , unix.stackexchange.com/questions/375743 , unix.stackexchange.com/questions/10394 , and unix.stackexchange.com/questions/26975 just for starters.
    – JdeBP
    Dec 13 '17 at 21:02
















  • Please unlearn the habit of using echo -ne. Use printf instead. There are several systems where echo -ne … will literally print -ne …
    – Fox
    Dec 13 '17 at 18:39






  • 2




    This is, by my count, at least six questions in one, which is not good. There should be one question per question. Moreover, so much of the background to this question would be improved from reading what we already have that covers this, including unix.stackexchange.com/questions/87469 , unix.stackexchange.com/questions/65803 , unix.stackexchange.com/questions/335648 , unix.stackexchange.com/questions/375743 , unix.stackexchange.com/questions/10394 , and unix.stackexchange.com/questions/26975 just for starters.
    – JdeBP
    Dec 13 '17 at 21:02















Please unlearn the habit of using echo -ne. Use printf instead. There are several systems where echo -ne … will literally print -ne …
– Fox
Dec 13 '17 at 18:39




Please unlearn the habit of using echo -ne. Use printf instead. There are several systems where echo -ne … will literally print -ne …
– Fox
Dec 13 '17 at 18:39




2




2




This is, by my count, at least six questions in one, which is not good. There should be one question per question. Moreover, so much of the background to this question would be improved from reading what we already have that covers this, including unix.stackexchange.com/questions/87469 , unix.stackexchange.com/questions/65803 , unix.stackexchange.com/questions/335648 , unix.stackexchange.com/questions/375743 , unix.stackexchange.com/questions/10394 , and unix.stackexchange.com/questions/26975 just for starters.
– JdeBP
Dec 13 '17 at 21:02




This is, by my count, at least six questions in one, which is not good. There should be one question per question. Moreover, so much of the background to this question would be improved from reading what we already have that covers this, including unix.stackexchange.com/questions/87469 , unix.stackexchange.com/questions/65803 , unix.stackexchange.com/questions/335648 , unix.stackexchange.com/questions/375743 , unix.stackexchange.com/questions/10394 , and unix.stackexchange.com/questions/26975 just for starters.
– JdeBP
Dec 13 '17 at 21:02










1 Answer
1






active

oldest

votes

















up vote
2
down vote













Many terminal emulators use the same escape sequences as XTerm, or similar. For XTerm, Escc is defined as "Full Reset (RIS)". It seems reasonable that a full reset would clear the scrollback buffer.




I have had no success using readline to bind to the sequence itself, but a workaround is



bind '"C-l": "C-aC-kprintf "\033c"C-m"'


This has some caveats. First, it puts the printf command in your shell history, which is not ideal. Second, it cannot be used while inputting a command; it overwrites the current input line.






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%2f410708%2fthe-easiest-way-to-clear-scrollback-buffer-of-terminal-some-deeper-explanation%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    Many terminal emulators use the same escape sequences as XTerm, or similar. For XTerm, Escc is defined as "Full Reset (RIS)". It seems reasonable that a full reset would clear the scrollback buffer.




    I have had no success using readline to bind to the sequence itself, but a workaround is



    bind '"C-l": "C-aC-kprintf "\033c"C-m"'


    This has some caveats. First, it puts the printf command in your shell history, which is not ideal. Second, it cannot be used while inputting a command; it overwrites the current input line.






    share|improve this answer
























      up vote
      2
      down vote













      Many terminal emulators use the same escape sequences as XTerm, or similar. For XTerm, Escc is defined as "Full Reset (RIS)". It seems reasonable that a full reset would clear the scrollback buffer.




      I have had no success using readline to bind to the sequence itself, but a workaround is



      bind '"C-l": "C-aC-kprintf "\033c"C-m"'


      This has some caveats. First, it puts the printf command in your shell history, which is not ideal. Second, it cannot be used while inputting a command; it overwrites the current input line.






      share|improve this answer






















        up vote
        2
        down vote










        up vote
        2
        down vote









        Many terminal emulators use the same escape sequences as XTerm, or similar. For XTerm, Escc is defined as "Full Reset (RIS)". It seems reasonable that a full reset would clear the scrollback buffer.




        I have had no success using readline to bind to the sequence itself, but a workaround is



        bind '"C-l": "C-aC-kprintf "\033c"C-m"'


        This has some caveats. First, it puts the printf command in your shell history, which is not ideal. Second, it cannot be used while inputting a command; it overwrites the current input line.






        share|improve this answer












        Many terminal emulators use the same escape sequences as XTerm, or similar. For XTerm, Escc is defined as "Full Reset (RIS)". It seems reasonable that a full reset would clear the scrollback buffer.




        I have had no success using readline to bind to the sequence itself, but a workaround is



        bind '"C-l": "C-aC-kprintf "\033c"C-m"'


        This has some caveats. First, it puts the printf command in your shell history, which is not ideal. Second, it cannot be used while inputting a command; it overwrites the current input line.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 13 '17 at 18:37









        Fox

        4,72111131




        4,72111131






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f410708%2fthe-easiest-way-to-clear-scrollback-buffer-of-terminal-some-deeper-explanation%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?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay