{"id":94,"date":"2011-09-10T17:25:39","date_gmt":"2011-09-10T11:55:39","guid":{"rendered":"http:\/\/askadmin.com\/?p=94"},"modified":"2015-04-07T14:25:49","modified_gmt":"2015-04-07T08:55:49","slug":"all-about-my-bash","status":"publish","type":"post","link":"https:\/\/askadmin.com\/aa\/all-about-my-bash\/","title":{"rendered":"# All About My bash #"},"content":{"rendered":"<p>I am not a linux guru ! . But\u00a0 in my work ,\u00a0 I do say hello\u00a0 at least once everyday \u00a0to my Linux servers\u00a0 from <em>bash<\/em> .<\/p>\n<p>Bash is a unix\/linux command shell to execute commands . You can find different command shells like\u00a0<span style=\"color: #99cc00;\"><em>tcsh,sh,zsh,bash\u00a0<\/em><\/span>in\u00a0<span style=\"color: #99cc00;\"><em>bin<\/em>\u00a0<\/span>directoryetc.,\u00a0. \u00a0But my favourite&amp;default command shell on our servers is &#8216;<span style=\"color: #99cc00;\">BASH<\/span>&#8216; .<\/p>\n<p>Controlling\u00a0bash seems interesting to me .<\/p>\n<p>Typing the command <span style=\"color: #99cc00;\"><em>history<\/em><\/span> will display all the commands used previously on the system.<\/p>\n<p>I exported commands to a file this way..<\/p>\n<p><span style=\"color: #99cc00;\"><strong>[root@c6 ~]#<\/strong><em> history &gt; history.txt<\/em><\/span><\/p>\n<p>you will find a file called \u00a0<em><span style=\"color: #99cc00;\">.bashrc<\/span><\/em> in each user&#8217;s \u00a0home\u00a0directory\u00a0.<\/p>\n<p><em>\u00a0I edited my .bashrc file\u00a0<\/em><\/p>\n<p><span style=\"color: #99cc00;\"><strong>[root@cf \/]#<\/strong> vi ~\/.bashrc<\/span><\/p>\n<p>and\u00a0added\u00a0below lines<\/p>\n<p><em><span style=\"color: #99cc00;\">export HISTSIZE=10000<\/span><\/em> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0( history will remember 10000 commands)<span class=\"Apple-style-span\" style=\"font-weight: normal;\">\u00a0<\/span><\/p>\n<p><em><span style=\"color: #99cc00;\">export HISTCONTROL=erasedups<\/span><\/em>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ( this will erase duplicated commands and keep only one copy of each comamnd )<\/p>\n<p><em><span style=\"color: #99cc00;\">shopt -s histappend\u00a0<\/span><\/em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 (this line says that commands not to be overwritten but appended)<span class=\"Apple-style-span\" style=\"font-weight: normal;\">\u00a0<\/span><\/p>\n<p>Ok.. alright.. , Now what If \u00a0I dont like to save the command history ? .I will just use one of the methods below.<\/p>\n<p>method 1#<\/p>\n<p>To clear bash history when i am on terminal \u00a0, i use the command <span style=\"color: #99cc00;\"><em>history -c\u00a0<\/em><\/span><\/p>\n<p><span style=\"color: #99cc00;\"><em><strong>[root@cf \/]#<\/strong> history -c<\/em><\/span><\/p>\n<p><span style=\"color: #000000;\">This will clear entire bash history whereas\u00a0<span style=\"color: #99cc00;\"><em>history -r<\/em><\/span> command will clear the current session history only.<\/span><span class=\"Apple-style-span\" style=\"font-weight: normal;\">\u00a0<\/span><\/p>\n<p><em><span style=\"color: #99cc00;\"><strong>[root@cf \/]#<\/strong> history -r<\/span><\/em><\/p>\n<p>method 2#<\/p>\n<p>clear bash history when logout the session<\/p>\n<p>edit .bash_logout \u00a0 file which we can find in every user home directory.<\/p>\n<p><span style=\"color: #99cc00;\"><em><strong>[root@cf ~]#<\/strong> vi ~\/.bash_logout<\/em> \u00a0 <span style=\"color: #000000;\">\u00a0press <span style=\"color: #99cc00;\">i<\/span> \u00a0to insert below lines in vim editor<\/span><\/span><\/p>\n<p><em><span style=\"color: #99cc00;\">\u00a0&gt;~\/.bash_history<\/span><\/em><\/p>\n<p><em><span style=\"color: #99cc00;\">sync;<\/span><\/em><\/p>\n<p>press escape and \u00a0type \u00a0<span style=\"color: #99cc00;\">:wq<\/span> \u00a0 and press enter \u00a0to save the changes in vim editor.<\/p>\n<p>This method will not \u00a0clear the history if you close the window without\u00a0logging out\u00a0from the terminal by using the command <em><span style=\"color: #99cc00;\">logout<\/span><\/em><\/p>\n<p>method 3 #<\/p>\n<p>The command \u00a0<span style=\"color: #99cc00;\">ln -sf \/dev\/null ~\/.bash_history<\/span> \u00a0will tell bash to send \u00a0history of commands to null, so it will not remember any commands that are typed in.<\/p>\n<p><span style=\"color: #99cc00;\">\u00a0<em><strong>[root@cf ~]#<\/strong> ln -sf \/dev\/null ~\/.bash_history<\/em><\/span><span class=\"Apple-style-span\" style=\"font-weight: normal;\">\u00a0<\/span><\/p>\n<p>And finally .. one thing I passionate about is ,receiving \u00a0bashhistory to my mail automatically . I will write it in my next post .<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am not a linux guru ! . But\u00a0 in my work ,\u00a0 I do say hello\u00a0 at least once everyday \u00a0to my Linux servers\u00a0 from bash . Bash is a unix\/linux command shell to execute commands . You can find different command shells like\u00a0tcsh,sh,zsh,bash\u00a0in\u00a0bin\u00a0directoryetc.,\u00a0. \u00a0But my favourite&amp;default command shell [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[7],"tags":[16,20,17,15,21,19,18],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>remove command history linux<\/title>\n<meta name=\"description\" content=\"remove command history linux\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/askadmin.com\/aa\/all-about-my-bash\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"remove command history linux\" \/>\n<meta property=\"og:description\" content=\"remove command history linux\" \/>\n<meta property=\"og:url\" content=\"https:\/\/askadmin.com\/aa\/all-about-my-bash\/\" \/>\n<meta property=\"og:site_name\" content=\"Ask Admin - A Lifelong Learner\" \/>\n<meta property=\"article:published_time\" content=\"2011-09-10T11:55:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-04-07T08:55:49+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"balu sreekanth\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/askadmin.com\/aa\/#website\",\"url\":\"https:\/\/askadmin.com\/aa\/\",\"name\":\"Ask Admin - A Lifelong Learner\",\"description\":\"Mobile App Development | IP Telephony | Linux\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/askadmin.com\/aa\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/askadmin.com\/aa\/all-about-my-bash\/#webpage\",\"url\":\"https:\/\/askadmin.com\/aa\/all-about-my-bash\/\",\"name\":\"remove command history linux\",\"isPartOf\":{\"@id\":\"https:\/\/askadmin.com\/aa\/#website\"},\"datePublished\":\"2011-09-10T11:55:39+00:00\",\"dateModified\":\"2015-04-07T08:55:49+00:00\",\"author\":{\"@id\":\"https:\/\/askadmin.com\/aa\/#\/schema\/person\/e1ff95d4a91ea001e25af3273533a345\"},\"description\":\"remove command history linux\",\"breadcrumb\":{\"@id\":\"https:\/\/askadmin.com\/aa\/all-about-my-bash\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/askadmin.com\/aa\/all-about-my-bash\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/askadmin.com\/aa\/all-about-my-bash\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/askadmin.com\/aa\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"# All About My bash #\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/askadmin.com\/aa\/#\/schema\/person\/e1ff95d4a91ea001e25af3273533a345\",\"name\":\"balu sreekanth\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/askadmin.com\/aa\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6aebf95935573dc70f536f1003a2fb8c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6aebf95935573dc70f536f1003a2fb8c?s=96&d=mm&r=g\",\"caption\":\"balu sreekanth\"},\"sameAs\":[\"http:\/\/askadmin.com\"],\"url\":\"https:\/\/askadmin.com\/aa\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"remove command history linux","description":"remove command history linux","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/askadmin.com\/aa\/all-about-my-bash\/","og_locale":"en_US","og_type":"article","og_title":"remove command history linux","og_description":"remove command history linux","og_url":"https:\/\/askadmin.com\/aa\/all-about-my-bash\/","og_site_name":"Ask Admin - A Lifelong Learner","article_published_time":"2011-09-10T11:55:39+00:00","article_modified_time":"2015-04-07T08:55:49+00:00","twitter_misc":{"Written by":"balu sreekanth","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/askadmin.com\/aa\/#website","url":"https:\/\/askadmin.com\/aa\/","name":"Ask Admin - A Lifelong Learner","description":"Mobile App Development | IP Telephony | Linux","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/askadmin.com\/aa\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/askadmin.com\/aa\/all-about-my-bash\/#webpage","url":"https:\/\/askadmin.com\/aa\/all-about-my-bash\/","name":"remove command history linux","isPartOf":{"@id":"https:\/\/askadmin.com\/aa\/#website"},"datePublished":"2011-09-10T11:55:39+00:00","dateModified":"2015-04-07T08:55:49+00:00","author":{"@id":"https:\/\/askadmin.com\/aa\/#\/schema\/person\/e1ff95d4a91ea001e25af3273533a345"},"description":"remove command history linux","breadcrumb":{"@id":"https:\/\/askadmin.com\/aa\/all-about-my-bash\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/askadmin.com\/aa\/all-about-my-bash\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/askadmin.com\/aa\/all-about-my-bash\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/askadmin.com\/aa\/"},{"@type":"ListItem","position":2,"name":"# All About My bash #"}]},{"@type":"Person","@id":"https:\/\/askadmin.com\/aa\/#\/schema\/person\/e1ff95d4a91ea001e25af3273533a345","name":"balu sreekanth","image":{"@type":"ImageObject","@id":"https:\/\/askadmin.com\/aa\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/6aebf95935573dc70f536f1003a2fb8c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6aebf95935573dc70f536f1003a2fb8c?s=96&d=mm&r=g","caption":"balu sreekanth"},"sameAs":["http:\/\/askadmin.com"],"url":"https:\/\/askadmin.com\/aa\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/askadmin.com\/aa\/wp-json\/wp\/v2\/posts\/94"}],"collection":[{"href":"https:\/\/askadmin.com\/aa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/askadmin.com\/aa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/askadmin.com\/aa\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/askadmin.com\/aa\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":16,"href":"https:\/\/askadmin.com\/aa\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":99,"href":"https:\/\/askadmin.com\/aa\/wp-json\/wp\/v2\/posts\/94\/revisions\/99"}],"wp:attachment":[{"href":"https:\/\/askadmin.com\/aa\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/askadmin.com\/aa\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/askadmin.com\/aa\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}