How to remove command-line history from a specific time period?

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








up vote
3
down vote

favorite












How can I remove command-line history over a specific time period?



Is it possible do so with only one command?










share|improve this question























  • Are you just trying to ensure that someone after you cannot see what you have done?
    – Charles Green
    Dec 12 '15 at 20:52










  • Basically, yes.
    – TellMeWhy
    Dec 12 '15 at 20:53










  • I just edit ~/.bash_history and delete the lines I don't want left around.
    – Doug Smythies
    Dec 12 '15 at 20:54






  • 2




    prepend your commands with a space. Eg enter ` gedit /etc/rc.local` Commands with a leading space do not get entered into history.
    – Charles Green
    Dec 12 '15 at 20:57






  • 2




    The thing is, .bash_history doesn't store commands based on time periods. It just adds commands one by one. You're much better off simply deleting the whole file. It will be recreated next time shell starts
    – Sergiy Kolodyazhnyy
    Dec 12 '15 at 20:59














up vote
3
down vote

favorite












How can I remove command-line history over a specific time period?



Is it possible do so with only one command?










share|improve this question























  • Are you just trying to ensure that someone after you cannot see what you have done?
    – Charles Green
    Dec 12 '15 at 20:52










  • Basically, yes.
    – TellMeWhy
    Dec 12 '15 at 20:53










  • I just edit ~/.bash_history and delete the lines I don't want left around.
    – Doug Smythies
    Dec 12 '15 at 20:54






  • 2




    prepend your commands with a space. Eg enter ` gedit /etc/rc.local` Commands with a leading space do not get entered into history.
    – Charles Green
    Dec 12 '15 at 20:57






  • 2




    The thing is, .bash_history doesn't store commands based on time periods. It just adds commands one by one. You're much better off simply deleting the whole file. It will be recreated next time shell starts
    – Sergiy Kolodyazhnyy
    Dec 12 '15 at 20:59












up vote
3
down vote

favorite









up vote
3
down vote

favorite











How can I remove command-line history over a specific time period?



Is it possible do so with only one command?










share|improve this question















How can I remove command-line history over a specific time period?



Is it possible do so with only one command?







command-line bash history






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 12 '15 at 21:32









muru

130k19275470




130k19275470










asked Dec 12 '15 at 20:46









TellMeWhy

7,4461661114




7,4461661114











  • Are you just trying to ensure that someone after you cannot see what you have done?
    – Charles Green
    Dec 12 '15 at 20:52










  • Basically, yes.
    – TellMeWhy
    Dec 12 '15 at 20:53










  • I just edit ~/.bash_history and delete the lines I don't want left around.
    – Doug Smythies
    Dec 12 '15 at 20:54






  • 2




    prepend your commands with a space. Eg enter ` gedit /etc/rc.local` Commands with a leading space do not get entered into history.
    – Charles Green
    Dec 12 '15 at 20:57






  • 2




    The thing is, .bash_history doesn't store commands based on time periods. It just adds commands one by one. You're much better off simply deleting the whole file. It will be recreated next time shell starts
    – Sergiy Kolodyazhnyy
    Dec 12 '15 at 20:59
















  • Are you just trying to ensure that someone after you cannot see what you have done?
    – Charles Green
    Dec 12 '15 at 20:52










  • Basically, yes.
    – TellMeWhy
    Dec 12 '15 at 20:53










  • I just edit ~/.bash_history and delete the lines I don't want left around.
    – Doug Smythies
    Dec 12 '15 at 20:54






  • 2




    prepend your commands with a space. Eg enter ` gedit /etc/rc.local` Commands with a leading space do not get entered into history.
    – Charles Green
    Dec 12 '15 at 20:57






  • 2




    The thing is, .bash_history doesn't store commands based on time periods. It just adds commands one by one. You're much better off simply deleting the whole file. It will be recreated next time shell starts
    – Sergiy Kolodyazhnyy
    Dec 12 '15 at 20:59















Are you just trying to ensure that someone after you cannot see what you have done?
– Charles Green
Dec 12 '15 at 20:52




Are you just trying to ensure that someone after you cannot see what you have done?
– Charles Green
Dec 12 '15 at 20:52












Basically, yes.
– TellMeWhy
Dec 12 '15 at 20:53




Basically, yes.
– TellMeWhy
Dec 12 '15 at 20:53












I just edit ~/.bash_history and delete the lines I don't want left around.
– Doug Smythies
Dec 12 '15 at 20:54




I just edit ~/.bash_history and delete the lines I don't want left around.
– Doug Smythies
Dec 12 '15 at 20:54




2




2




prepend your commands with a space. Eg enter ` gedit /etc/rc.local` Commands with a leading space do not get entered into history.
– Charles Green
Dec 12 '15 at 20:57




prepend your commands with a space. Eg enter ` gedit /etc/rc.local` Commands with a leading space do not get entered into history.
– Charles Green
Dec 12 '15 at 20:57




2




2




The thing is, .bash_history doesn't store commands based on time periods. It just adds commands one by one. You're much better off simply deleting the whole file. It will be recreated next time shell starts
– Sergiy Kolodyazhnyy
Dec 12 '15 at 20:59




The thing is, .bash_history doesn't store commands based on time periods. It just adds commands one by one. You're much better off simply deleting the whole file. It will be recreated next time shell starts
– Sergiy Kolodyazhnyy
Dec 12 '15 at 20:59










1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










While it is possible to store the time at which a command was run, the history manipulation commands do not use time as a reference. Look up HISTTIMEFORMAT in man bash:



HISTTIMEFORMAT
If this variable is set and not null, its value is used as a
format string for strftime(3) to print the time stamp associated
with each history entry displayed by the history builtin. If
this variable is set, time stamps are written to the history
file so they may be preserved across shell sessions. This uses
the history comment character to distinguish timestamps from
other history lines.


If you had set HISTTIMEFORMAT before you ran the commands you wanted to delete, your .bash_history would have lines like so:



$ tail -4 ~/.bash_history 
#1449955320
history
#1449955329
history -w


Then you could take advantage of the Unix timestamps to delete them, using awk, for example:



awk -F# -v end=$(date -d yesterday +%s) 
-v start=$(date -d 'now - 3 days' +%s)
'$2 < start || $2 > end print; getline; print'


I'm not sure how this command will work with multi-line commands, but you could maybe count the timestamps to get the number assigned to a command, and then use history to delete it.




If you hadn't set HISTTIMEFORMAT beforehand, then you'll have to do this manually.






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    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: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    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%2faskubuntu.com%2fquestions%2f708906%2fhow-to-remove-command-line-history-from-a-specific-time-period%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
    3
    down vote



    accepted










    While it is possible to store the time at which a command was run, the history manipulation commands do not use time as a reference. Look up HISTTIMEFORMAT in man bash:



    HISTTIMEFORMAT
    If this variable is set and not null, its value is used as a
    format string for strftime(3) to print the time stamp associated
    with each history entry displayed by the history builtin. If
    this variable is set, time stamps are written to the history
    file so they may be preserved across shell sessions. This uses
    the history comment character to distinguish timestamps from
    other history lines.


    If you had set HISTTIMEFORMAT before you ran the commands you wanted to delete, your .bash_history would have lines like so:



    $ tail -4 ~/.bash_history 
    #1449955320
    history
    #1449955329
    history -w


    Then you could take advantage of the Unix timestamps to delete them, using awk, for example:



    awk -F# -v end=$(date -d yesterday +%s) 
    -v start=$(date -d 'now - 3 days' +%s)
    '$2 < start || $2 > end print; getline; print'


    I'm not sure how this command will work with multi-line commands, but you could maybe count the timestamps to get the number assigned to a command, and then use history to delete it.




    If you hadn't set HISTTIMEFORMAT beforehand, then you'll have to do this manually.






    share|improve this answer
























      up vote
      3
      down vote



      accepted










      While it is possible to store the time at which a command was run, the history manipulation commands do not use time as a reference. Look up HISTTIMEFORMAT in man bash:



      HISTTIMEFORMAT
      If this variable is set and not null, its value is used as a
      format string for strftime(3) to print the time stamp associated
      with each history entry displayed by the history builtin. If
      this variable is set, time stamps are written to the history
      file so they may be preserved across shell sessions. This uses
      the history comment character to distinguish timestamps from
      other history lines.


      If you had set HISTTIMEFORMAT before you ran the commands you wanted to delete, your .bash_history would have lines like so:



      $ tail -4 ~/.bash_history 
      #1449955320
      history
      #1449955329
      history -w


      Then you could take advantage of the Unix timestamps to delete them, using awk, for example:



      awk -F# -v end=$(date -d yesterday +%s) 
      -v start=$(date -d 'now - 3 days' +%s)
      '$2 < start || $2 > end print; getline; print'


      I'm not sure how this command will work with multi-line commands, but you could maybe count the timestamps to get the number assigned to a command, and then use history to delete it.




      If you hadn't set HISTTIMEFORMAT beforehand, then you'll have to do this manually.






      share|improve this answer






















        up vote
        3
        down vote



        accepted







        up vote
        3
        down vote



        accepted






        While it is possible to store the time at which a command was run, the history manipulation commands do not use time as a reference. Look up HISTTIMEFORMAT in man bash:



        HISTTIMEFORMAT
        If this variable is set and not null, its value is used as a
        format string for strftime(3) to print the time stamp associated
        with each history entry displayed by the history builtin. If
        this variable is set, time stamps are written to the history
        file so they may be preserved across shell sessions. This uses
        the history comment character to distinguish timestamps from
        other history lines.


        If you had set HISTTIMEFORMAT before you ran the commands you wanted to delete, your .bash_history would have lines like so:



        $ tail -4 ~/.bash_history 
        #1449955320
        history
        #1449955329
        history -w


        Then you could take advantage of the Unix timestamps to delete them, using awk, for example:



        awk -F# -v end=$(date -d yesterday +%s) 
        -v start=$(date -d 'now - 3 days' +%s)
        '$2 < start || $2 > end print; getline; print'


        I'm not sure how this command will work with multi-line commands, but you could maybe count the timestamps to get the number assigned to a command, and then use history to delete it.




        If you hadn't set HISTTIMEFORMAT beforehand, then you'll have to do this manually.






        share|improve this answer












        While it is possible to store the time at which a command was run, the history manipulation commands do not use time as a reference. Look up HISTTIMEFORMAT in man bash:



        HISTTIMEFORMAT
        If this variable is set and not null, its value is used as a
        format string for strftime(3) to print the time stamp associated
        with each history entry displayed by the history builtin. If
        this variable is set, time stamps are written to the history
        file so they may be preserved across shell sessions. This uses
        the history comment character to distinguish timestamps from
        other history lines.


        If you had set HISTTIMEFORMAT before you ran the commands you wanted to delete, your .bash_history would have lines like so:



        $ tail -4 ~/.bash_history 
        #1449955320
        history
        #1449955329
        history -w


        Then you could take advantage of the Unix timestamps to delete them, using awk, for example:



        awk -F# -v end=$(date -d yesterday +%s) 
        -v start=$(date -d 'now - 3 days' +%s)
        '$2 < start || $2 > end print; getline; print'


        I'm not sure how this command will work with multi-line commands, but you could maybe count the timestamps to get the number assigned to a command, and then use history to delete it.




        If you hadn't set HISTTIMEFORMAT beforehand, then you'll have to do this manually.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 12 '15 at 21:29









        muru

        130k19275470




        130k19275470



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f708906%2fhow-to-remove-command-line-history-from-a-specific-time-period%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            pylint3 and pip3 broken

            Missing snmpget and snmpwalk

            How to enroll fingerprints to Ubuntu 17.10 with VFS491