How to remove a single line from history?

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











up vote
166
down vote

favorite
63












I'm working in Mac OSX, so I guess I'm using bash...?



Sometimes I enter something that I don't want to be remembered in the history. How do I remove it?










share|improve this question























  • Very similar: Is there any way to keep a command from being added to your history?
    – ire_and_curses
    Sep 26 '12 at 19:42














up vote
166
down vote

favorite
63












I'm working in Mac OSX, so I guess I'm using bash...?



Sometimes I enter something that I don't want to be remembered in the history. How do I remove it?










share|improve this question























  • Very similar: Is there any way to keep a command from being added to your history?
    – ire_and_curses
    Sep 26 '12 at 19:42












up vote
166
down vote

favorite
63









up vote
166
down vote

favorite
63






63





I'm working in Mac OSX, so I guess I'm using bash...?



Sometimes I enter something that I don't want to be remembered in the history. How do I remove it?










share|improve this question















I'm working in Mac OSX, so I guess I'm using bash...?



Sometimes I enter something that I don't want to be remembered in the history. How do I remove it?







bash shell command-line command-history






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 26 '12 at 19:54









ire_and_curses

9,59222731




9,59222731










asked Sep 26 '12 at 17:41









B Seven

2,26441518




2,26441518











  • Very similar: Is there any way to keep a command from being added to your history?
    – ire_and_curses
    Sep 26 '12 at 19:42
















  • Very similar: Is there any way to keep a command from being added to your history?
    – ire_and_curses
    Sep 26 '12 at 19:42















Very similar: Is there any way to keep a command from being added to your history?
– ire_and_curses
Sep 26 '12 at 19:42




Very similar: Is there any way to keep a command from being added to your history?
– ire_and_curses
Sep 26 '12 at 19:42










7 Answers
7






active

oldest

votes

















up vote
272
down vote



accepted










Preventative measures



If you want to run a command without saving it in history, prepend it with an extra space



prompt$ echo saved
prompt$ echo not saved
> # ^ extra space


For this to work you need either ignorespace or ignoreboth in HISTCONTROL. For example, run



HISTCONTROL=ignorespace


To make this setting persistent, put it in your .bashrc.



Post-mortem clean-up



If you've already run the command, and want to remove it from history, first use



history


to display the list of commands in your history. Find the number next to the one you want to delete (e.g. 1234) and run



history -d 1234





share|improve this answer






















  • It worked. I think we need to source ~/.bashrc after modifying it...
    – B Seven
    Sep 26 '12 at 18:00






  • 3




    @jw013 I set PROMPT_COMMAND to history -a, in that case it is already written to the history file, rather than on exit under normal configuration. Specifically: mywiki.wooledge.org/BashFAQ/088
    – jordanm
    Oct 22 '12 at 3:54







  • 3




    After deleting a single line, you need to write out the current history to your $HISTFILE using history -w. Otherwise when you exit, the deleted line is still there!
    – Felipe Alvarez
    Jan 18 '17 at 2:39






  • 1




    +1 to the comment above; using history -w after history -d num was exactly what I needed -- that critical tidbit should be added to the answer, otherwise a user might think a temp delete from the current shell is actually permanent.
    – michael
    Jul 11 '17 at 3:58






  • 1




    @BobStein history -w is necessary for entries that already have been written to the .bash_history file. How to reproduce (e.g. on CentOS 7 with stock configuration): 1. login 2. enter command echo foo 3. logout 4. login again 5. delete entry for echo foo 6. logout 7. login again: entry is still there. Depending on how you configure your bash history perhaps you can reproduce this issue in other ways - i.e. if you provoke history writing before logout.
    – maxschlepzig
    Oct 12 at 19:53

















up vote
41
down vote














  1. To clear all your history, use



    history -c



  2. To delete a single line, use



    history -d linenumber






share|improve this answer





























    up vote
    6
    down vote













    You always can edit and remove entries from ~/.bash_history, useful when you want to remove either one entry or more than one entry






    share|improve this answer
















    • 1




      Most likely these entries will be reintroduced when you exit the shell.
      – l0b0
      Jul 17 at 2:56

















    up vote
    5
    down vote













    I have this in my ~/.bashrc, which makes the command $ forget delete the previous command from history



    function forget() grep -oP '^ d+') - 1); 






    share|improve this answer




















    • That seems a little complicated. Wouldn't history -d $( history | tail -n 1 | cut -f 1 -d " " ) be simpler?
      – seumasmac
      Oct 3 '15 at 1:40







    • 1




      history | tail -n1 is the history command itself, so deleting that number gets the wrong entry. However, history -d $( history | awk 'ENDprint $1-1' ) combines the line select, field select, and subtraction.
      – dave_thompson_085
      Oct 3 '15 at 3:03










    • Any chance someone could help out with portin this to zshell?
      – Alex S
      Oct 14 '15 at 13:27

















    up vote
    4
    down vote













    If you want to forget the entire bash session, you can kill the current bash process. Since the variable $$ hold the pid of the current shell, you can do:



    kill -9 $$





    share|improve this answer



























      up vote
      1
      down vote













      You need to write the changes after you cleared the history. And if you wouldn't like to have the history wipe command in your history then you need to run the command like that:



      history -c && history -w && logout



      Good luck.






      share|improve this answer



























        up vote
        -1
        down vote













        Adding another point suppose if you want to delete a range of history lines

        You can use below script.

        Below example will delete history output from line 1 to line 150.

        for i in `history | awk 'NR > 1 && NR <=150print $1'`; do history -d $i; done





        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: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          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%2f49214%2fhow-to-remove-a-single-line-from-history%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          7 Answers
          7






          active

          oldest

          votes








          7 Answers
          7






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          272
          down vote



          accepted










          Preventative measures



          If you want to run a command without saving it in history, prepend it with an extra space



          prompt$ echo saved
          prompt$ echo not saved
          > # ^ extra space


          For this to work you need either ignorespace or ignoreboth in HISTCONTROL. For example, run



          HISTCONTROL=ignorespace


          To make this setting persistent, put it in your .bashrc.



          Post-mortem clean-up



          If you've already run the command, and want to remove it from history, first use



          history


          to display the list of commands in your history. Find the number next to the one you want to delete (e.g. 1234) and run



          history -d 1234





          share|improve this answer






















          • It worked. I think we need to source ~/.bashrc after modifying it...
            – B Seven
            Sep 26 '12 at 18:00






          • 3




            @jw013 I set PROMPT_COMMAND to history -a, in that case it is already written to the history file, rather than on exit under normal configuration. Specifically: mywiki.wooledge.org/BashFAQ/088
            – jordanm
            Oct 22 '12 at 3:54







          • 3




            After deleting a single line, you need to write out the current history to your $HISTFILE using history -w. Otherwise when you exit, the deleted line is still there!
            – Felipe Alvarez
            Jan 18 '17 at 2:39






          • 1




            +1 to the comment above; using history -w after history -d num was exactly what I needed -- that critical tidbit should be added to the answer, otherwise a user might think a temp delete from the current shell is actually permanent.
            – michael
            Jul 11 '17 at 3:58






          • 1




            @BobStein history -w is necessary for entries that already have been written to the .bash_history file. How to reproduce (e.g. on CentOS 7 with stock configuration): 1. login 2. enter command echo foo 3. logout 4. login again 5. delete entry for echo foo 6. logout 7. login again: entry is still there. Depending on how you configure your bash history perhaps you can reproduce this issue in other ways - i.e. if you provoke history writing before logout.
            – maxschlepzig
            Oct 12 at 19:53














          up vote
          272
          down vote



          accepted










          Preventative measures



          If you want to run a command without saving it in history, prepend it with an extra space



          prompt$ echo saved
          prompt$ echo not saved
          > # ^ extra space


          For this to work you need either ignorespace or ignoreboth in HISTCONTROL. For example, run



          HISTCONTROL=ignorespace


          To make this setting persistent, put it in your .bashrc.



          Post-mortem clean-up



          If you've already run the command, and want to remove it from history, first use



          history


          to display the list of commands in your history. Find the number next to the one you want to delete (e.g. 1234) and run



          history -d 1234





          share|improve this answer






















          • It worked. I think we need to source ~/.bashrc after modifying it...
            – B Seven
            Sep 26 '12 at 18:00






          • 3




            @jw013 I set PROMPT_COMMAND to history -a, in that case it is already written to the history file, rather than on exit under normal configuration. Specifically: mywiki.wooledge.org/BashFAQ/088
            – jordanm
            Oct 22 '12 at 3:54







          • 3




            After deleting a single line, you need to write out the current history to your $HISTFILE using history -w. Otherwise when you exit, the deleted line is still there!
            – Felipe Alvarez
            Jan 18 '17 at 2:39






          • 1




            +1 to the comment above; using history -w after history -d num was exactly what I needed -- that critical tidbit should be added to the answer, otherwise a user might think a temp delete from the current shell is actually permanent.
            – michael
            Jul 11 '17 at 3:58






          • 1




            @BobStein history -w is necessary for entries that already have been written to the .bash_history file. How to reproduce (e.g. on CentOS 7 with stock configuration): 1. login 2. enter command echo foo 3. logout 4. login again 5. delete entry for echo foo 6. logout 7. login again: entry is still there. Depending on how you configure your bash history perhaps you can reproduce this issue in other ways - i.e. if you provoke history writing before logout.
            – maxschlepzig
            Oct 12 at 19:53












          up vote
          272
          down vote



          accepted







          up vote
          272
          down vote



          accepted






          Preventative measures



          If you want to run a command without saving it in history, prepend it with an extra space



          prompt$ echo saved
          prompt$ echo not saved
          > # ^ extra space


          For this to work you need either ignorespace or ignoreboth in HISTCONTROL. For example, run



          HISTCONTROL=ignorespace


          To make this setting persistent, put it in your .bashrc.



          Post-mortem clean-up



          If you've already run the command, and want to remove it from history, first use



          history


          to display the list of commands in your history. Find the number next to the one you want to delete (e.g. 1234) and run



          history -d 1234





          share|improve this answer














          Preventative measures



          If you want to run a command without saving it in history, prepend it with an extra space



          prompt$ echo saved
          prompt$ echo not saved
          > # ^ extra space


          For this to work you need either ignorespace or ignoreboth in HISTCONTROL. For example, run



          HISTCONTROL=ignorespace


          To make this setting persistent, put it in your .bashrc.



          Post-mortem clean-up



          If you've already run the command, and want to remove it from history, first use



          history


          to display the list of commands in your history. Find the number next to the one you want to delete (e.g. 1234) and run



          history -d 1234






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 26 '15 at 13:03

























          answered Sep 26 '12 at 17:49









          jw013

          35.8k699125




          35.8k699125











          • It worked. I think we need to source ~/.bashrc after modifying it...
            – B Seven
            Sep 26 '12 at 18:00






          • 3




            @jw013 I set PROMPT_COMMAND to history -a, in that case it is already written to the history file, rather than on exit under normal configuration. Specifically: mywiki.wooledge.org/BashFAQ/088
            – jordanm
            Oct 22 '12 at 3:54







          • 3




            After deleting a single line, you need to write out the current history to your $HISTFILE using history -w. Otherwise when you exit, the deleted line is still there!
            – Felipe Alvarez
            Jan 18 '17 at 2:39






          • 1




            +1 to the comment above; using history -w after history -d num was exactly what I needed -- that critical tidbit should be added to the answer, otherwise a user might think a temp delete from the current shell is actually permanent.
            – michael
            Jul 11 '17 at 3:58






          • 1




            @BobStein history -w is necessary for entries that already have been written to the .bash_history file. How to reproduce (e.g. on CentOS 7 with stock configuration): 1. login 2. enter command echo foo 3. logout 4. login again 5. delete entry for echo foo 6. logout 7. login again: entry is still there. Depending on how you configure your bash history perhaps you can reproduce this issue in other ways - i.e. if you provoke history writing before logout.
            – maxschlepzig
            Oct 12 at 19:53
















          • It worked. I think we need to source ~/.bashrc after modifying it...
            – B Seven
            Sep 26 '12 at 18:00






          • 3




            @jw013 I set PROMPT_COMMAND to history -a, in that case it is already written to the history file, rather than on exit under normal configuration. Specifically: mywiki.wooledge.org/BashFAQ/088
            – jordanm
            Oct 22 '12 at 3:54







          • 3




            After deleting a single line, you need to write out the current history to your $HISTFILE using history -w. Otherwise when you exit, the deleted line is still there!
            – Felipe Alvarez
            Jan 18 '17 at 2:39






          • 1




            +1 to the comment above; using history -w after history -d num was exactly what I needed -- that critical tidbit should be added to the answer, otherwise a user might think a temp delete from the current shell is actually permanent.
            – michael
            Jul 11 '17 at 3:58






          • 1




            @BobStein history -w is necessary for entries that already have been written to the .bash_history file. How to reproduce (e.g. on CentOS 7 with stock configuration): 1. login 2. enter command echo foo 3. logout 4. login again 5. delete entry for echo foo 6. logout 7. login again: entry is still there. Depending on how you configure your bash history perhaps you can reproduce this issue in other ways - i.e. if you provoke history writing before logout.
            – maxschlepzig
            Oct 12 at 19:53















          It worked. I think we need to source ~/.bashrc after modifying it...
          – B Seven
          Sep 26 '12 at 18:00




          It worked. I think we need to source ~/.bashrc after modifying it...
          – B Seven
          Sep 26 '12 at 18:00




          3




          3




          @jw013 I set PROMPT_COMMAND to history -a, in that case it is already written to the history file, rather than on exit under normal configuration. Specifically: mywiki.wooledge.org/BashFAQ/088
          – jordanm
          Oct 22 '12 at 3:54





          @jw013 I set PROMPT_COMMAND to history -a, in that case it is already written to the history file, rather than on exit under normal configuration. Specifically: mywiki.wooledge.org/BashFAQ/088
          – jordanm
          Oct 22 '12 at 3:54





          3




          3




          After deleting a single line, you need to write out the current history to your $HISTFILE using history -w. Otherwise when you exit, the deleted line is still there!
          – Felipe Alvarez
          Jan 18 '17 at 2:39




          After deleting a single line, you need to write out the current history to your $HISTFILE using history -w. Otherwise when you exit, the deleted line is still there!
          – Felipe Alvarez
          Jan 18 '17 at 2:39




          1




          1




          +1 to the comment above; using history -w after history -d num was exactly what I needed -- that critical tidbit should be added to the answer, otherwise a user might think a temp delete from the current shell is actually permanent.
          – michael
          Jul 11 '17 at 3:58




          +1 to the comment above; using history -w after history -d num was exactly what I needed -- that critical tidbit should be added to the answer, otherwise a user might think a temp delete from the current shell is actually permanent.
          – michael
          Jul 11 '17 at 3:58




          1




          1




          @BobStein history -w is necessary for entries that already have been written to the .bash_history file. How to reproduce (e.g. on CentOS 7 with stock configuration): 1. login 2. enter command echo foo 3. logout 4. login again 5. delete entry for echo foo 6. logout 7. login again: entry is still there. Depending on how you configure your bash history perhaps you can reproduce this issue in other ways - i.e. if you provoke history writing before logout.
          – maxschlepzig
          Oct 12 at 19:53




          @BobStein history -w is necessary for entries that already have been written to the .bash_history file. How to reproduce (e.g. on CentOS 7 with stock configuration): 1. login 2. enter command echo foo 3. logout 4. login again 5. delete entry for echo foo 6. logout 7. login again: entry is still there. Depending on how you configure your bash history perhaps you can reproduce this issue in other ways - i.e. if you provoke history writing before logout.
          – maxschlepzig
          Oct 12 at 19:53












          up vote
          41
          down vote














          1. To clear all your history, use



            history -c



          2. To delete a single line, use



            history -d linenumber






          share|improve this answer


























            up vote
            41
            down vote














            1. To clear all your history, use



              history -c



            2. To delete a single line, use



              history -d linenumber






            share|improve this answer
























              up vote
              41
              down vote










              up vote
              41
              down vote










              1. To clear all your history, use



                history -c



              2. To delete a single line, use



                history -d linenumber






              share|improve this answer















              1. To clear all your history, use



                history -c



              2. To delete a single line, use



                history -d linenumber







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Jan 9 '15 at 12:23









              terdon

              127k31245422




              127k31245422










              answered Jan 9 '15 at 12:13









              soumyaranjan

              57645




              57645




















                  up vote
                  6
                  down vote













                  You always can edit and remove entries from ~/.bash_history, useful when you want to remove either one entry or more than one entry






                  share|improve this answer
















                  • 1




                    Most likely these entries will be reintroduced when you exit the shell.
                    – l0b0
                    Jul 17 at 2:56














                  up vote
                  6
                  down vote













                  You always can edit and remove entries from ~/.bash_history, useful when you want to remove either one entry or more than one entry






                  share|improve this answer
















                  • 1




                    Most likely these entries will be reintroduced when you exit the shell.
                    – l0b0
                    Jul 17 at 2:56












                  up vote
                  6
                  down vote










                  up vote
                  6
                  down vote









                  You always can edit and remove entries from ~/.bash_history, useful when you want to remove either one entry or more than one entry






                  share|improve this answer












                  You always can edit and remove entries from ~/.bash_history, useful when you want to remove either one entry or more than one entry







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 4 '16 at 8:19









                  Weslor

                  16911




                  16911







                  • 1




                    Most likely these entries will be reintroduced when you exit the shell.
                    – l0b0
                    Jul 17 at 2:56












                  • 1




                    Most likely these entries will be reintroduced when you exit the shell.
                    – l0b0
                    Jul 17 at 2:56







                  1




                  1




                  Most likely these entries will be reintroduced when you exit the shell.
                  – l0b0
                  Jul 17 at 2:56




                  Most likely these entries will be reintroduced when you exit the shell.
                  – l0b0
                  Jul 17 at 2:56










                  up vote
                  5
                  down vote













                  I have this in my ~/.bashrc, which makes the command $ forget delete the previous command from history



                  function forget() grep -oP '^ d+') - 1); 






                  share|improve this answer




















                  • That seems a little complicated. Wouldn't history -d $( history | tail -n 1 | cut -f 1 -d " " ) be simpler?
                    – seumasmac
                    Oct 3 '15 at 1:40







                  • 1




                    history | tail -n1 is the history command itself, so deleting that number gets the wrong entry. However, history -d $( history | awk 'ENDprint $1-1' ) combines the line select, field select, and subtraction.
                    – dave_thompson_085
                    Oct 3 '15 at 3:03










                  • Any chance someone could help out with portin this to zshell?
                    – Alex S
                    Oct 14 '15 at 13:27














                  up vote
                  5
                  down vote













                  I have this in my ~/.bashrc, which makes the command $ forget delete the previous command from history



                  function forget() grep -oP '^ d+') - 1); 






                  share|improve this answer




















                  • That seems a little complicated. Wouldn't history -d $( history | tail -n 1 | cut -f 1 -d " " ) be simpler?
                    – seumasmac
                    Oct 3 '15 at 1:40







                  • 1




                    history | tail -n1 is the history command itself, so deleting that number gets the wrong entry. However, history -d $( history | awk 'ENDprint $1-1' ) combines the line select, field select, and subtraction.
                    – dave_thompson_085
                    Oct 3 '15 at 3:03










                  • Any chance someone could help out with portin this to zshell?
                    – Alex S
                    Oct 14 '15 at 13:27












                  up vote
                  5
                  down vote










                  up vote
                  5
                  down vote









                  I have this in my ~/.bashrc, which makes the command $ forget delete the previous command from history



                  function forget() grep -oP '^ d+') - 1); 






                  share|improve this answer












                  I have this in my ~/.bashrc, which makes the command $ forget delete the previous command from history



                  function forget() grep -oP '^ d+') - 1); 







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 3 '15 at 1:33









                  Ryan Haining

                  18115




                  18115











                  • That seems a little complicated. Wouldn't history -d $( history | tail -n 1 | cut -f 1 -d " " ) be simpler?
                    – seumasmac
                    Oct 3 '15 at 1:40







                  • 1




                    history | tail -n1 is the history command itself, so deleting that number gets the wrong entry. However, history -d $( history | awk 'ENDprint $1-1' ) combines the line select, field select, and subtraction.
                    – dave_thompson_085
                    Oct 3 '15 at 3:03










                  • Any chance someone could help out with portin this to zshell?
                    – Alex S
                    Oct 14 '15 at 13:27
















                  • That seems a little complicated. Wouldn't history -d $( history | tail -n 1 | cut -f 1 -d " " ) be simpler?
                    – seumasmac
                    Oct 3 '15 at 1:40







                  • 1




                    history | tail -n1 is the history command itself, so deleting that number gets the wrong entry. However, history -d $( history | awk 'ENDprint $1-1' ) combines the line select, field select, and subtraction.
                    – dave_thompson_085
                    Oct 3 '15 at 3:03










                  • Any chance someone could help out with portin this to zshell?
                    – Alex S
                    Oct 14 '15 at 13:27















                  That seems a little complicated. Wouldn't history -d $( history | tail -n 1 | cut -f 1 -d " " ) be simpler?
                  – seumasmac
                  Oct 3 '15 at 1:40





                  That seems a little complicated. Wouldn't history -d $( history | tail -n 1 | cut -f 1 -d " " ) be simpler?
                  – seumasmac
                  Oct 3 '15 at 1:40





                  1




                  1




                  history | tail -n1 is the history command itself, so deleting that number gets the wrong entry. However, history -d $( history | awk 'ENDprint $1-1' ) combines the line select, field select, and subtraction.
                  – dave_thompson_085
                  Oct 3 '15 at 3:03




                  history | tail -n1 is the history command itself, so deleting that number gets the wrong entry. However, history -d $( history | awk 'ENDprint $1-1' ) combines the line select, field select, and subtraction.
                  – dave_thompson_085
                  Oct 3 '15 at 3:03












                  Any chance someone could help out with portin this to zshell?
                  – Alex S
                  Oct 14 '15 at 13:27




                  Any chance someone could help out with portin this to zshell?
                  – Alex S
                  Oct 14 '15 at 13:27










                  up vote
                  4
                  down vote













                  If you want to forget the entire bash session, you can kill the current bash process. Since the variable $$ hold the pid of the current shell, you can do:



                  kill -9 $$





                  share|improve this answer
























                    up vote
                    4
                    down vote













                    If you want to forget the entire bash session, you can kill the current bash process. Since the variable $$ hold the pid of the current shell, you can do:



                    kill -9 $$





                    share|improve this answer






















                      up vote
                      4
                      down vote










                      up vote
                      4
                      down vote









                      If you want to forget the entire bash session, you can kill the current bash process. Since the variable $$ hold the pid of the current shell, you can do:



                      kill -9 $$





                      share|improve this answer












                      If you want to forget the entire bash session, you can kill the current bash process. Since the variable $$ hold the pid of the current shell, you can do:



                      kill -9 $$






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jan 26 '17 at 17:53









                      Bruno Bronosky

                      1,89511112




                      1,89511112




















                          up vote
                          1
                          down vote













                          You need to write the changes after you cleared the history. And if you wouldn't like to have the history wipe command in your history then you need to run the command like that:



                          history -c && history -w && logout



                          Good luck.






                          share|improve this answer
























                            up vote
                            1
                            down vote













                            You need to write the changes after you cleared the history. And if you wouldn't like to have the history wipe command in your history then you need to run the command like that:



                            history -c && history -w && logout



                            Good luck.






                            share|improve this answer






















                              up vote
                              1
                              down vote










                              up vote
                              1
                              down vote









                              You need to write the changes after you cleared the history. And if you wouldn't like to have the history wipe command in your history then you need to run the command like that:



                              history -c && history -w && logout



                              Good luck.






                              share|improve this answer












                              You need to write the changes after you cleared the history. And if you wouldn't like to have the history wipe command in your history then you need to run the command like that:



                              history -c && history -w && logout



                              Good luck.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Mar 17 at 17:29









                              user882786

                              191




                              191




















                                  up vote
                                  -1
                                  down vote













                                  Adding another point suppose if you want to delete a range of history lines

                                  You can use below script.

                                  Below example will delete history output from line 1 to line 150.

                                  for i in `history | awk 'NR > 1 && NR <=150print $1'`; do history -d $i; done





                                  share|improve this answer
























                                    up vote
                                    -1
                                    down vote













                                    Adding another point suppose if you want to delete a range of history lines

                                    You can use below script.

                                    Below example will delete history output from line 1 to line 150.

                                    for i in `history | awk 'NR > 1 && NR <=150print $1'`; do history -d $i; done





                                    share|improve this answer






















                                      up vote
                                      -1
                                      down vote










                                      up vote
                                      -1
                                      down vote









                                      Adding another point suppose if you want to delete a range of history lines

                                      You can use below script.

                                      Below example will delete history output from line 1 to line 150.

                                      for i in `history | awk 'NR > 1 && NR <=150print $1'`; do history -d $i; done





                                      share|improve this answer












                                      Adding another point suppose if you want to delete a range of history lines

                                      You can use below script.

                                      Below example will delete history output from line 1 to line 150.

                                      for i in `history | awk 'NR > 1 && NR <=150print $1'`; do history -d $i; done






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Nov 30 at 8:21









                                      Praveen Kumar BS

                                      1,162138




                                      1,162138



























                                          draft saved

                                          draft discarded
















































                                          Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid


                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.

                                          To learn more, see our tips on writing great answers.





                                          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                          Please pay close attention to the following guidance:


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid


                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.

                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f49214%2fhow-to-remove-a-single-line-from-history%23new-answer', 'question_page');

                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown






                                          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