history isn't preserved in zsh

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











up vote
4
down vote

favorite












Whenever I open a new instance of a terminal, the history is empty. Why is that? Do I need to set something up? In bash there's no need for this, though.










share|improve this question















migrated from serverfault.com Sep 1 '17 at 22:30


This question came from our site for system and network administrators.














  • Not sure about zsh, but by default bash writes to his history files upon exit, which means if you have not used it before and open some shells, they will all show now history until at least one logs out, thereby writing its history file.
    – DopeGhoti
    Sep 1 '17 at 22:34














up vote
4
down vote

favorite












Whenever I open a new instance of a terminal, the history is empty. Why is that? Do I need to set something up? In bash there's no need for this, though.










share|improve this question















migrated from serverfault.com Sep 1 '17 at 22:30


This question came from our site for system and network administrators.














  • Not sure about zsh, but by default bash writes to his history files upon exit, which means if you have not used it before and open some shells, they will all show now history until at least one logs out, thereby writing its history file.
    – DopeGhoti
    Sep 1 '17 at 22:34












up vote
4
down vote

favorite









up vote
4
down vote

favorite











Whenever I open a new instance of a terminal, the history is empty. Why is that? Do I need to set something up? In bash there's no need for this, though.










share|improve this question















Whenever I open a new instance of a terminal, the history is empty. Why is that? Do I need to set something up? In bash there's no need for this, though.







zsh command-history






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 1 '17 at 22:36









Gilles

512k12010151547




512k12010151547










asked Sep 1 '17 at 21:51







Jodari











migrated from serverfault.com Sep 1 '17 at 22:30


This question came from our site for system and network administrators.






migrated from serverfault.com Sep 1 '17 at 22:30


This question came from our site for system and network administrators.













  • Not sure about zsh, but by default bash writes to his history files upon exit, which means if you have not used it before and open some shells, they will all show now history until at least one logs out, thereby writing its history file.
    – DopeGhoti
    Sep 1 '17 at 22:34
















  • Not sure about zsh, but by default bash writes to his history files upon exit, which means if you have not used it before and open some shells, they will all show now history until at least one logs out, thereby writing its history file.
    – DopeGhoti
    Sep 1 '17 at 22:34















Not sure about zsh, but by default bash writes to his history files upon exit, which means if you have not used it before and open some shells, they will all show now history until at least one logs out, thereby writing its history file.
– DopeGhoti
Sep 1 '17 at 22:34




Not sure about zsh, but by default bash writes to his history files upon exit, which means if you have not used it before and open some shells, they will all show now history until at least one logs out, thereby writing its history file.
– DopeGhoti
Sep 1 '17 at 22:34










2 Answers
2






active

oldest

votes

















up vote
5
down vote













Bash and zsh have different defaults. Zsh doesn't save the history to a file by default.



When you run zsh without a configuration file, it displays a configuration interface. In this configuration interface, select



(1) Configure settings for history, i.e. command lines remembered
and saved by the shell. (Recommended.)


then review the proposed settings and select



# (0) Remember edits and return to main menu (does not save file yet)


Repeat for the other submenus for (2) completion, (3) keybindings and (4) options, then select



(0) Exit, saving the new settings. They will take effect immediately.


from the main menu.



The recommended history-related settings are



HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
setopt appendhistory


I would use a different name for the history file, to indicate it's zsh's history file. And 1000 lines can be increased on a modern system.



HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt appendhistory


These lines go into ~/.zshrc, by the way.






share|improve this answer



























    up vote
    2
    down vote













    While the existing answer is correct, I thought it might be worth adding that there's possibly a better option than appendhistory for saving your history and this is SHARE_HISTORY.



    From the docs SHARE_HISTORY "both imports new commands from the history file, and also causes your typed commands to be appended to the history file". This means that shells are aware of each other's history as well without having to close the current one or open a new one.



    So, all together you'd set it like this:



    HISTFILE=~/.zsh_history
    HISTSIZE=10000
    SAVEHIST=1000
    setopt SHARE_HISTORY





    share|improve this answer


















    • 1




      +1 and welcome to U/L, but personally I prefer INC_APPEND_HISTORY_TIME, which writes to history from all terminals as above, but that history "will not be available immediately from other instances of the shell that are using the same history file". This makes more sense to me, because then I can traverse each terminal's history independently, but it's still all logged.
      – Sparhawk
      Sep 22 at 13:16






    • 1




      Thanks! Yeah that's fair enough and I can totally see why INC_APPEND_HISTORY_TIME might make more logical sense. I probably shouldn't have said "better", I guess it's just a matter of personal preference at this point!
      – bert
      Sep 22 at 13:19











    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%2f389881%2fhistory-isnt-preserved-in-zsh%23new-answer', 'question_page');

    );

    Post as a guest





























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    5
    down vote













    Bash and zsh have different defaults. Zsh doesn't save the history to a file by default.



    When you run zsh without a configuration file, it displays a configuration interface. In this configuration interface, select



    (1) Configure settings for history, i.e. command lines remembered
    and saved by the shell. (Recommended.)


    then review the proposed settings and select



    # (0) Remember edits and return to main menu (does not save file yet)


    Repeat for the other submenus for (2) completion, (3) keybindings and (4) options, then select



    (0) Exit, saving the new settings. They will take effect immediately.


    from the main menu.



    The recommended history-related settings are



    HISTFILE=~/.histfile
    HISTSIZE=1000
    SAVEHIST=1000
    setopt appendhistory


    I would use a different name for the history file, to indicate it's zsh's history file. And 1000 lines can be increased on a modern system.



    HISTFILE=~/.zsh_history
    HISTSIZE=10000
    SAVEHIST=10000
    setopt appendhistory


    These lines go into ~/.zshrc, by the way.






    share|improve this answer
























      up vote
      5
      down vote













      Bash and zsh have different defaults. Zsh doesn't save the history to a file by default.



      When you run zsh without a configuration file, it displays a configuration interface. In this configuration interface, select



      (1) Configure settings for history, i.e. command lines remembered
      and saved by the shell. (Recommended.)


      then review the proposed settings and select



      # (0) Remember edits and return to main menu (does not save file yet)


      Repeat for the other submenus for (2) completion, (3) keybindings and (4) options, then select



      (0) Exit, saving the new settings. They will take effect immediately.


      from the main menu.



      The recommended history-related settings are



      HISTFILE=~/.histfile
      HISTSIZE=1000
      SAVEHIST=1000
      setopt appendhistory


      I would use a different name for the history file, to indicate it's zsh's history file. And 1000 lines can be increased on a modern system.



      HISTFILE=~/.zsh_history
      HISTSIZE=10000
      SAVEHIST=10000
      setopt appendhistory


      These lines go into ~/.zshrc, by the way.






      share|improve this answer






















        up vote
        5
        down vote










        up vote
        5
        down vote









        Bash and zsh have different defaults. Zsh doesn't save the history to a file by default.



        When you run zsh without a configuration file, it displays a configuration interface. In this configuration interface, select



        (1) Configure settings for history, i.e. command lines remembered
        and saved by the shell. (Recommended.)


        then review the proposed settings and select



        # (0) Remember edits and return to main menu (does not save file yet)


        Repeat for the other submenus for (2) completion, (3) keybindings and (4) options, then select



        (0) Exit, saving the new settings. They will take effect immediately.


        from the main menu.



        The recommended history-related settings are



        HISTFILE=~/.histfile
        HISTSIZE=1000
        SAVEHIST=1000
        setopt appendhistory


        I would use a different name for the history file, to indicate it's zsh's history file. And 1000 lines can be increased on a modern system.



        HISTFILE=~/.zsh_history
        HISTSIZE=10000
        SAVEHIST=10000
        setopt appendhistory


        These lines go into ~/.zshrc, by the way.






        share|improve this answer












        Bash and zsh have different defaults. Zsh doesn't save the history to a file by default.



        When you run zsh without a configuration file, it displays a configuration interface. In this configuration interface, select



        (1) Configure settings for history, i.e. command lines remembered
        and saved by the shell. (Recommended.)


        then review the proposed settings and select



        # (0) Remember edits and return to main menu (does not save file yet)


        Repeat for the other submenus for (2) completion, (3) keybindings and (4) options, then select



        (0) Exit, saving the new settings. They will take effect immediately.


        from the main menu.



        The recommended history-related settings are



        HISTFILE=~/.histfile
        HISTSIZE=1000
        SAVEHIST=1000
        setopt appendhistory


        I would use a different name for the history file, to indicate it's zsh's history file. And 1000 lines can be increased on a modern system.



        HISTFILE=~/.zsh_history
        HISTSIZE=10000
        SAVEHIST=10000
        setopt appendhistory


        These lines go into ~/.zshrc, by the way.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 1 '17 at 22:36









        Gilles

        512k12010151547




        512k12010151547






















            up vote
            2
            down vote













            While the existing answer is correct, I thought it might be worth adding that there's possibly a better option than appendhistory for saving your history and this is SHARE_HISTORY.



            From the docs SHARE_HISTORY "both imports new commands from the history file, and also causes your typed commands to be appended to the history file". This means that shells are aware of each other's history as well without having to close the current one or open a new one.



            So, all together you'd set it like this:



            HISTFILE=~/.zsh_history
            HISTSIZE=10000
            SAVEHIST=1000
            setopt SHARE_HISTORY





            share|improve this answer


















            • 1




              +1 and welcome to U/L, but personally I prefer INC_APPEND_HISTORY_TIME, which writes to history from all terminals as above, but that history "will not be available immediately from other instances of the shell that are using the same history file". This makes more sense to me, because then I can traverse each terminal's history independently, but it's still all logged.
              – Sparhawk
              Sep 22 at 13:16






            • 1




              Thanks! Yeah that's fair enough and I can totally see why INC_APPEND_HISTORY_TIME might make more logical sense. I probably shouldn't have said "better", I guess it's just a matter of personal preference at this point!
              – bert
              Sep 22 at 13:19















            up vote
            2
            down vote













            While the existing answer is correct, I thought it might be worth adding that there's possibly a better option than appendhistory for saving your history and this is SHARE_HISTORY.



            From the docs SHARE_HISTORY "both imports new commands from the history file, and also causes your typed commands to be appended to the history file". This means that shells are aware of each other's history as well without having to close the current one or open a new one.



            So, all together you'd set it like this:



            HISTFILE=~/.zsh_history
            HISTSIZE=10000
            SAVEHIST=1000
            setopt SHARE_HISTORY





            share|improve this answer


















            • 1




              +1 and welcome to U/L, but personally I prefer INC_APPEND_HISTORY_TIME, which writes to history from all terminals as above, but that history "will not be available immediately from other instances of the shell that are using the same history file". This makes more sense to me, because then I can traverse each terminal's history independently, but it's still all logged.
              – Sparhawk
              Sep 22 at 13:16






            • 1




              Thanks! Yeah that's fair enough and I can totally see why INC_APPEND_HISTORY_TIME might make more logical sense. I probably shouldn't have said "better", I guess it's just a matter of personal preference at this point!
              – bert
              Sep 22 at 13:19













            up vote
            2
            down vote










            up vote
            2
            down vote









            While the existing answer is correct, I thought it might be worth adding that there's possibly a better option than appendhistory for saving your history and this is SHARE_HISTORY.



            From the docs SHARE_HISTORY "both imports new commands from the history file, and also causes your typed commands to be appended to the history file". This means that shells are aware of each other's history as well without having to close the current one or open a new one.



            So, all together you'd set it like this:



            HISTFILE=~/.zsh_history
            HISTSIZE=10000
            SAVEHIST=1000
            setopt SHARE_HISTORY





            share|improve this answer














            While the existing answer is correct, I thought it might be worth adding that there's possibly a better option than appendhistory for saving your history and this is SHARE_HISTORY.



            From the docs SHARE_HISTORY "both imports new commands from the history file, and also causes your typed commands to be appended to the history file". This means that shells are aware of each other's history as well without having to close the current one or open a new one.



            So, all together you'd set it like this:



            HISTFILE=~/.zsh_history
            HISTSIZE=10000
            SAVEHIST=1000
            setopt SHARE_HISTORY






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Sep 22 at 12:48









            Goro

            6,20152763




            6,20152763










            answered Sep 22 at 12:44









            bert

            1284




            1284







            • 1




              +1 and welcome to U/L, but personally I prefer INC_APPEND_HISTORY_TIME, which writes to history from all terminals as above, but that history "will not be available immediately from other instances of the shell that are using the same history file". This makes more sense to me, because then I can traverse each terminal's history independently, but it's still all logged.
              – Sparhawk
              Sep 22 at 13:16






            • 1




              Thanks! Yeah that's fair enough and I can totally see why INC_APPEND_HISTORY_TIME might make more logical sense. I probably shouldn't have said "better", I guess it's just a matter of personal preference at this point!
              – bert
              Sep 22 at 13:19













            • 1




              +1 and welcome to U/L, but personally I prefer INC_APPEND_HISTORY_TIME, which writes to history from all terminals as above, but that history "will not be available immediately from other instances of the shell that are using the same history file". This makes more sense to me, because then I can traverse each terminal's history independently, but it's still all logged.
              – Sparhawk
              Sep 22 at 13:16






            • 1




              Thanks! Yeah that's fair enough and I can totally see why INC_APPEND_HISTORY_TIME might make more logical sense. I probably shouldn't have said "better", I guess it's just a matter of personal preference at this point!
              – bert
              Sep 22 at 13:19








            1




            1




            +1 and welcome to U/L, but personally I prefer INC_APPEND_HISTORY_TIME, which writes to history from all terminals as above, but that history "will not be available immediately from other instances of the shell that are using the same history file". This makes more sense to me, because then I can traverse each terminal's history independently, but it's still all logged.
            – Sparhawk
            Sep 22 at 13:16




            +1 and welcome to U/L, but personally I prefer INC_APPEND_HISTORY_TIME, which writes to history from all terminals as above, but that history "will not be available immediately from other instances of the shell that are using the same history file". This makes more sense to me, because then I can traverse each terminal's history independently, but it's still all logged.
            – Sparhawk
            Sep 22 at 13:16




            1




            1




            Thanks! Yeah that's fair enough and I can totally see why INC_APPEND_HISTORY_TIME might make more logical sense. I probably shouldn't have said "better", I guess it's just a matter of personal preference at this point!
            – bert
            Sep 22 at 13:19





            Thanks! Yeah that's fair enough and I can totally see why INC_APPEND_HISTORY_TIME might make more logical sense. I probably shouldn't have said "better", I guess it's just a matter of personal preference at this point!
            – bert
            Sep 22 at 13:19


















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f389881%2fhistory-isnt-preserved-in-zsh%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