{"id":5156,"date":"2026-08-30T08:40:32","date_gmt":"2026-08-29T23:40:32","guid":{"rendered":"https:\/\/donguri3.net\/server-tech\/bash-history-customize-2\/"},"modified":"2026-08-30T08:40:33","modified_gmt":"2026-08-29T23:40:33","slug":"bash-history-customize","status":"publish","type":"post","link":"https:\/\/donguri3.net\/en\/server-tech\/linux-server-network\/bash-history-customize\/","title":{"rendered":"Recommended Settings to Supercharge Bash History"},"content":{"rendered":"<p>When working daily in the terminal on Linux or macOS, the &#8220;history&#8221; feature for recalling previously executed commands is indispensable.<br \/>However, with the default settings, the number of history entries is small, meaning those useful records quickly disappear. Additionally, it can be frustrating to use because you cannot tell when a command was executed.<\/p>\n<hr \/>\n<h2>Objectives<\/h2>\n<ul>\n<li>\n<p><strong>Long-term storage of previously executed commands<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>Clear display of execution dates and times<\/strong><\/p>\n<\/li>\n<li>\n<p><strong>Properly retain history even when multiple terminals are open<\/strong><\/p>\n<\/li>\n<\/ul>\n<h2>Issues<\/h2>\n<ol>\n<li>\n<p>By default, the number of history entries (HISTSIZE) is small, retaining only a few thousand lines<\/p>\n<\/li>\n<li>\n<p>There is no date and time information, making it difficult to know when a command was run<\/p>\n<\/li>\n<li>\n<p>When using multiple terminals, only the history of the last closed window is saved, and other history may be lost<\/p>\n<\/li>\n<\/ol>\n<hr \/>\n<h2>Solution: Configuration Example<\/h2>\n<p>Add the following settings to <code>~\/.bashrc<\/code> and apply them.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\"># Add to ~\/.bashrc\nexport HISTSIZE=100000 # Number of entries to keep in memory\nexport HISTFILESIZE=200000 # Number of entries to save in ~\/.bash_history\nshopt -s histappend # Append instead of overwriting\nexport PROMPT_COMMAND=&quot;history -a&quot; # Save after every command execution\nexport HISTTIMEFORMAT=&quot;%F %T &quot; # Display date and time<\/pre>\n<p>To apply the settings, run the following:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">source&lt;\/span&gt; ~\/.bashrc<\/pre>\n<hr \/>\n<h2>Verifying the Effects<\/h2>\n<h3>1. Check if the history size has increased<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">echo $HISTSIZE $HISTFILESIZE<\/pre>\n<p>Output example:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">100000 200000<\/pre>\n<h3>2. Check if dates and times are displayed in the history<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">history | head<\/pre>\n<p><span style=\"font-size: 1.6rem;\">Output example:<\/span><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\"> 1000 2025-08-18 20:12:35 ls -l\n1001 2025-08-18 20:12:40 git status<\/pre>\n<hr \/>\n<h2>Conclusion<\/h2>\n<ul>\n<li>\n<p>Increasing <code>HISTSIZE<\/code> and <code>HISTFILESIZE<\/code> allows for long-term history storage<\/p>\n<\/li>\n<li>\n<p><code>HISTTIMEFORMAT<\/code> makes command execution times easy to understand<\/p>\n<\/li>\n<li>\n<p>Using <code>histappend<\/code> and <code>PROMPT_COMMAND=\"history -a\"<\/code> prevents history from being lost across multiple terminals<\/p>\n<\/li>\n<\/ul>\n<p>Just by adding these 5 lines to your <code>.bashrc<\/code>, terminal work becomes significantly more comfortable.<br \/>If you want to make better use of your past commands, please give it a try.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When working daily in the terminal on Linux or macOS, the &#8220;history&#8221; feature for recalling previous [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":1975,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/donguri3.net\/?p=1969","footnotes":""},"categories":[1170],"tags":[51,105,663,540,104],"class_list":["post-5156","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-server-network","tag-git","tag-linux","tag-663","tag-540","tag-104","en-US"],"_links":{"self":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/5156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/comments?post=5156"}],"version-history":[{"count":1,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/5156\/revisions"}],"predecessor-version":[{"id":5159,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/posts\/5156\/revisions\/5159"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/media\/1975"}],"wp:attachment":[{"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/media?parent=5156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/categories?post=5156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/donguri3.net\/wp-json\/wp\/v2\/tags?post=5156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}