bash HISTSIZE vs. HISTFILESIZE?

后端 未结 2 1502
轮回少年
轮回少年 2021-01-29 17:36

What is the difference in HISTSIZE vs. HISTFILESIZE?

They are used to extend bash history beyond the default 500 lines.

There seems to

2条回答
  •  终归单人心
    2021-01-29 18:35

    Building on top of what arturomp have said and in an effort to make it a bit clearer.

    Assumming you have 2000-something long history..

    ~$ history
        1  sdf
        2  fghdfgjf
        3  fghfghdf
       ..  ..
     2027  78
     2028  57
     2029  yu45u
    

    You can cut down what you are shown with HISTSIZE

    ~$ HISTSIZE=5
    ~$ history
     2026  546
     2027  78
     2028  56
     2029  yu45u
     2030  HISTSIZE=5
    

    Now, no matter how many commands you type, only the last 5 will be recorded.

    ~$ ABC
    ~$ GGH
    ~$ GSDHFG
    ~$ JFDR
    ~$ ABSDDS
    ~$ AHFGHFD
    
    
    ~$ history
        1  sdf
        2  fghdfgjf
        3  fghfghdf
       ..  ..
     2028  56
     2029  yu45u
     2030  HISTSIZE=5
     2031  GGH
     2032  GSDHFG
     2033  JFDR
     2034  ABSDDS
     2035  AHFGHFD
    

    We can clearly see that our first command ("ABC") is not in the history since only the last 5 commands were recorded.

    Now, the total history is stored in a file (.bash_history) and you can alter how long this file gets with the HISTFILESIZE. For example with a 2033 HISTFILESIZE, in my case I would have this:

    ~$ history
        1  fghfghdf
        2  gegege
        3  gege
       ..  ..
     2028  HISTSIZE=5
     2029  GGH
     2030  GSDHFG
     2031  JFDR
     2032  ABSDDS
     2033  AHFGHFD
    

提交回复
热议问题