{"id":294,"date":"2011-08-04T14:08:14","date_gmt":"2011-08-04T13:08:14","guid":{"rendered":"http:\/\/blogs.silicontechnix.com\/?p=294"},"modified":"2011-08-04T14:08:14","modified_gmt":"2011-08-04T13:08:14","slug":"take-control-of-your-bash_history","status":"publish","type":"post","link":"https:\/\/blogs.silicontechnix.com\/?p=294","title":{"rendered":"Take control of your bash_history"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>I spend most of my time working in front of a black and white terminal of remote <acronym class=\"uttAcronym\" title=\"Secure Shell\">SSH<\/acronym> connections to various servers.<\/p>\n<p>This means that I use <strong>bash <\/strong>(as my preferred shell) most of the day. And bash history is a very important feature of bash that saves me much time by recalling previous commands I have typed.<\/p>\n<p>Here are some tricks on how you can optimize with some simple configurations settings the usage your bash history.<\/p>\n<p><strong>1. Append to History<\/strong><\/p>\n<pre class=\"brush:bash\">history -a<\/pre>\n<p>Append the new history lines (history lines entered since the beginning of the current Bash session) to the history file.<\/p>\n<p><strong>2. Clear History<\/strong><\/p>\n<pre class=\"brush:bash\">history -c<\/pre>\n<p>(clear the history)<\/p>\n<p><strong>3. Write History to file<\/strong><\/p>\n<pre class=\"brush:bash\">history -w <\/pre>\n<p>(write to the file &ndash; overwrite!)<\/p>\n<p><strong>4. Dont save duplicate commands in the history<\/strong><\/p>\n<pre class=\"brush:bash\">HISTCONTROL=ignoreboth<\/pre>\n<p><strong>5. Size of the history:<\/strong><\/p>\n<pre class=\"brush:bash\">HISTSIZE=500<\/pre>\n<p><strong>HISTSIZE<\/strong>: The number of commands to remember in the command history. The default value is 500.<\/p>\n<p>How do you set these 4-5 options? Either export them in your environment in your personal bash configuration file (<strong>~\/.bashrc<\/strong>) or in the global bash configuration file (<strong>\/etc\/bash.bashrc<\/strong>).<\/p>\n<pre class=\"brush:bash\">export HISTCONTROL=ignoreboth\r\nexport HISTSIZE=500<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; I spend most of my time working in front of a black and white terminal of remote SSH connections to various servers. This means that I use bash (as my preferred shell) most of the day. And bash history is a very important feature of bash that saves me much time by recalling previous [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"yes","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[95,127],"tags":[],"class_list":["post-294","post","type-post","status-publish","format-standard","hentry","category-system-administration","category-tips"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p12j6H-4K","_links":{"self":[{"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=\/wp\/v2\/posts\/294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=294"}],"version-history":[{"count":10,"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=\/wp\/v2\/posts\/294\/revisions"}],"predecessor-version":[{"id":304,"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=\/wp\/v2\/posts\/294\/revisions\/304"}],"wp:attachment":[{"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}