How do I make my bash login session “autosave” its history? [duplicate]

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











up vote
0
down vote

favorite













This question already has an answer here:



  • How to protect against purge of bash history?

    1 answer



  • Preserve bash history in multiple terminal windows

    20 answers



IIANM, bash saves its history to ~/.bash_history (or to $HISTFILE) on exit from a login shell session. But - what if you want to occasionally persist it for fear of the shell getting prematurely killed (as in SIGKILL or power failure)? Is this possible without burdening the system or the shell session experience?







share|improve this question













marked as duplicate by Kiwy, Jeff Schaller, Romeo Ninov, Gilles bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
May 3 at 12:33


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 2




    This is a good read - BashFAQ/088 - How can I avoid losing any history lines?
    – Inian
    May 3 at 6:53










  • @Yaron: That question is related, not the same, since I'm not addressing the race condition. Also, it doesn't have a very satisying answer...
    – einpoklum
    May 3 at 7:46










  • @einpoklum - the answer describes: How turn history on with every command - won't it answer your needs?
    – Yaron
    May 3 at 7:53










  • Read about bash eternal history.
    – Isaac
    May 3 at 10:54














up vote
0
down vote

favorite













This question already has an answer here:



  • How to protect against purge of bash history?

    1 answer



  • Preserve bash history in multiple terminal windows

    20 answers



IIANM, bash saves its history to ~/.bash_history (or to $HISTFILE) on exit from a login shell session. But - what if you want to occasionally persist it for fear of the shell getting prematurely killed (as in SIGKILL or power failure)? Is this possible without burdening the system or the shell session experience?







share|improve this question













marked as duplicate by Kiwy, Jeff Schaller, Romeo Ninov, Gilles bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
May 3 at 12:33


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 2




    This is a good read - BashFAQ/088 - How can I avoid losing any history lines?
    – Inian
    May 3 at 6:53










  • @Yaron: That question is related, not the same, since I'm not addressing the race condition. Also, it doesn't have a very satisying answer...
    – einpoklum
    May 3 at 7:46










  • @einpoklum - the answer describes: How turn history on with every command - won't it answer your needs?
    – Yaron
    May 3 at 7:53










  • Read about bash eternal history.
    – Isaac
    May 3 at 10:54












up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • How to protect against purge of bash history?

    1 answer



  • Preserve bash history in multiple terminal windows

    20 answers



IIANM, bash saves its history to ~/.bash_history (or to $HISTFILE) on exit from a login shell session. But - what if you want to occasionally persist it for fear of the shell getting prematurely killed (as in SIGKILL or power failure)? Is this possible without burdening the system or the shell session experience?







share|improve this question














This question already has an answer here:



  • How to protect against purge of bash history?

    1 answer



  • Preserve bash history in multiple terminal windows

    20 answers



IIANM, bash saves its history to ~/.bash_history (or to $HISTFILE) on exit from a login shell session. But - what if you want to occasionally persist it for fear of the shell getting prematurely killed (as in SIGKILL or power failure)? Is this possible without burdening the system or the shell session experience?





This question already has an answer here:



  • How to protect against purge of bash history?

    1 answer



  • Preserve bash history in multiple terminal windows

    20 answers









share|improve this question












share|improve this question




share|improve this question








edited May 3 at 12:32









Gilles

504k1189951522




504k1189951522









asked May 3 at 6:48









einpoklum

1,93641845




1,93641845




marked as duplicate by Kiwy, Jeff Schaller, Romeo Ninov, Gilles bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
May 3 at 12:33


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Kiwy, Jeff Schaller, Romeo Ninov, Gilles bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
May 3 at 12:33


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









  • 2




    This is a good read - BashFAQ/088 - How can I avoid losing any history lines?
    – Inian
    May 3 at 6:53










  • @Yaron: That question is related, not the same, since I'm not addressing the race condition. Also, it doesn't have a very satisying answer...
    – einpoklum
    May 3 at 7:46










  • @einpoklum - the answer describes: How turn history on with every command - won't it answer your needs?
    – Yaron
    May 3 at 7:53










  • Read about bash eternal history.
    – Isaac
    May 3 at 10:54












  • 2




    This is a good read - BashFAQ/088 - How can I avoid losing any history lines?
    – Inian
    May 3 at 6:53










  • @Yaron: That question is related, not the same, since I'm not addressing the race condition. Also, it doesn't have a very satisying answer...
    – einpoklum
    May 3 at 7:46










  • @einpoklum - the answer describes: How turn history on with every command - won't it answer your needs?
    – Yaron
    May 3 at 7:53










  • Read about bash eternal history.
    – Isaac
    May 3 at 10:54







2




2




This is a good read - BashFAQ/088 - How can I avoid losing any history lines?
– Inian
May 3 at 6:53




This is a good read - BashFAQ/088 - How can I avoid losing any history lines?
– Inian
May 3 at 6:53












@Yaron: That question is related, not the same, since I'm not addressing the race condition. Also, it doesn't have a very satisying answer...
– einpoklum
May 3 at 7:46




@Yaron: That question is related, not the same, since I'm not addressing the race condition. Also, it doesn't have a very satisying answer...
– einpoklum
May 3 at 7:46












@einpoklum - the answer describes: How turn history on with every command - won't it answer your needs?
– Yaron
May 3 at 7:53




@einpoklum - the answer describes: How turn history on with every command - won't it answer your needs?
– Yaron
May 3 at 7:53












Read about bash eternal history.
– Isaac
May 3 at 10:54




Read about bash eternal history.
– Isaac
May 3 at 10:54










1 Answer
1






active

oldest

votes

















up vote
0
down vote













By default, Bash saves it's history on exit from shell. Thus it will lose it's current history if it's killed non-gracefully.



You can save your current Bash history by running:



$ history -a


Knowing that, you can make Bash save it's history after each executed command, by running history -a after each executed command. One way to do is via the Bash prompt:



PROMPT_COMMAND='history -a'


This works because the Bash prompt will execute $PS1, $PROMPT_COMMAND, and more, on each new prompt.



Here is a great blog post that got me onto the idea: https://sanctum.geek.nz/arabesque/better-bash-history/






share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    By default, Bash saves it's history on exit from shell. Thus it will lose it's current history if it's killed non-gracefully.



    You can save your current Bash history by running:



    $ history -a


    Knowing that, you can make Bash save it's history after each executed command, by running history -a after each executed command. One way to do is via the Bash prompt:



    PROMPT_COMMAND='history -a'


    This works because the Bash prompt will execute $PS1, $PROMPT_COMMAND, and more, on each new prompt.



    Here is a great blog post that got me onto the idea: https://sanctum.geek.nz/arabesque/better-bash-history/






    share|improve this answer



























      up vote
      0
      down vote













      By default, Bash saves it's history on exit from shell. Thus it will lose it's current history if it's killed non-gracefully.



      You can save your current Bash history by running:



      $ history -a


      Knowing that, you can make Bash save it's history after each executed command, by running history -a after each executed command. One way to do is via the Bash prompt:



      PROMPT_COMMAND='history -a'


      This works because the Bash prompt will execute $PS1, $PROMPT_COMMAND, and more, on each new prompt.



      Here is a great blog post that got me onto the idea: https://sanctum.geek.nz/arabesque/better-bash-history/






      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        By default, Bash saves it's history on exit from shell. Thus it will lose it's current history if it's killed non-gracefully.



        You can save your current Bash history by running:



        $ history -a


        Knowing that, you can make Bash save it's history after each executed command, by running history -a after each executed command. One way to do is via the Bash prompt:



        PROMPT_COMMAND='history -a'


        This works because the Bash prompt will execute $PS1, $PROMPT_COMMAND, and more, on each new prompt.



        Here is a great blog post that got me onto the idea: https://sanctum.geek.nz/arabesque/better-bash-history/






        share|improve this answer















        By default, Bash saves it's history on exit from shell. Thus it will lose it's current history if it's killed non-gracefully.



        You can save your current Bash history by running:



        $ history -a


        Knowing that, you can make Bash save it's history after each executed command, by running history -a after each executed command. One way to do is via the Bash prompt:



        PROMPT_COMMAND='history -a'


        This works because the Bash prompt will execute $PS1, $PROMPT_COMMAND, and more, on each new prompt.



        Here is a great blog post that got me onto the idea: https://sanctum.geek.nz/arabesque/better-bash-history/







        share|improve this answer















        share|improve this answer



        share|improve this answer








        edited May 3 at 8:47


























        answered May 3 at 8:23









        aude

        333




        333












            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