{"id":1990,"date":"2024-07-11T16:19:47","date_gmt":"2024-07-11T10:49:47","guid":{"rendered":"https:\/\/chennaiwebhosting.in\/blog\/?p=1990"},"modified":"2024-07-11T16:42:41","modified_gmt":"2024-07-11T11:12:41","slug":"how-to-clear-terminal-history-in-linux","status":"publish","type":"post","link":"https:\/\/chennaiwebhosting.in\/blog\/how-to-clear-terminal-history-in-linux\/","title":{"rendered":"#1 How to Clear terminal history in Linux"},"content":{"rendered":"<p>Clear terminal history in Linux can be done using various methods depending on your needs. Here are a few common ways:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-675\" src=\"https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/1-XOr2r7MKd2gn_TkagMcI0g-edited.png\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" srcset=\"https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/1-XOr2r7MKd2gn_TkagMcI0g-edited.png 610w, https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/1-XOr2r7MKd2gn_TkagMcI0g-edited-300x188.png 300w\" alt=\"\" width=\"610\" height=\"382\" \/><\/figure>\n<\/div>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/chennaiwebhosting.in\/blog\/how-to-clear-terminal-history-in-linux\/#Method_1_Clear_terminal_history_in_Linux_for_Current_Session\" >Method 1: Clear terminal history in Linux for Current Session<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/chennaiwebhosting.in\/blog\/how-to-clear-terminal-history-in-linux\/#Method_2_Clearing_history_by_editing_the_Bash_History_File\" >Method 2: Clearing history by editing the Bash History File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/chennaiwebhosting.in\/blog\/how-to-clear-terminal-history-in-linux\/#Method_3_Clearing_history_without_editing_the_Bash_History_File\" >Method 3: Clearing history without editing the Bash History File<\/a><\/li><\/ul><\/nav><\/div>\n<h3 id=\"method-1-clear-terminal-history-in-linux-for-current-session\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Method_1_Clear_terminal_history_in_Linux_for_Current_Session\"><\/span>Method 1: Clear terminal history in Linux for Current Session<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ol>\n<li><strong>Clear history command buffer:<\/strong><\/li>\n<\/ol>\n<pre class=\"wp-block-code\">   history -c<\/pre>\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-676\" src=\"https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image.png\" sizes=\"auto, (max-width: 684px) 100vw, 684px\" srcset=\"https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image.png 684w, https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image-300x84.png 300w\" alt=\"Clear terminal history in Linux\" width=\"637\" height=\"178\" \/><\/figure>\n<p>This command clears the history for the current session. Clear terminal history in Linux<\/p>\n<ol start=\"2\">\n<li><strong>Remove the history file:<\/strong><\/li>\n<\/ol>\n<pre class=\"wp-block-code\">  rm ~\/.bash_history<\/pre>\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-677\" src=\"https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image-1.png\" sizes=\"auto, (max-width: 578px) 100vw, 578px\" srcset=\"https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image-1.png 578w, https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image-1-300x65.png 300w\" alt=\"\" width=\"643\" height=\"139\" \/><\/figure>\n<p>&nbsp;<\/p>\n<p>This command deletes the .bash_history file, which contains the history of all commands executed in the terminal.<\/p>\n<ol start=\"3\">\n<li><strong>Clear history and update:<\/strong><\/li>\n<\/ol>\n<pre class=\"wp-block-code\"> history -c &amp;amp;&amp;amp; history -w<\/pre>\n<p>The history -c command clears the history in memory, and history -w writes the changes to the .bash_history file.<\/p>\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-678\" src=\"https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image-2.png\" sizes=\"auto, (max-width: 825px) 100vw, 825px\" srcset=\"https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image-2.png 825w, https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image-2-300x76.png 300w, https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image-2-768x195.png 768w\" alt=\"\" width=\"663\" height=\"168\" \/><\/figure>\n<h3 id=\"method-2-clearing-history-by-editing-the-bash-history-file\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Method_2_Clearing_history_by_editing_the_Bash_History_File\"><\/span>Method 2: Clearing history by editing the Bash History File<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ol>\n<li>To clear the command history in Linux by editing the Bash history file, you can manually edit the history file associated with your shell. The default Bash history file is usually ~\/.bash_history. Here are the steps to clear the history using this method:<\/li>\n<li>Open a terminal.<\/li>\n<li>Use a text editor (such as nano, vi, or gedit) to open the Bash history file:<\/li>\n<\/ol>\n<pre class=\"wp-block-preformatted\">vi ~\/.bash_history<\/pre>\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-680\" src=\"https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image-6.png\" sizes=\"auto, (max-width: 886px) 100vw, 886px\" srcset=\"https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image-6.png 886w, https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image-6-300x28.png 300w, https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image-6-768x71.png 768w\" alt=\"\" width=\"692\" height=\"64\" \/><\/figure>\n<p>Output:<\/p>\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-681\" src=\"https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image-7.png\" sizes=\"auto, (max-width: 1022px) 100vw, 1022px\" srcset=\"https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image-7.png 1022w, https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image-7-300x62.png 300w, https:\/\/vpswebhostingindia.com\/blog\/wp-content\/uploads\/2024\/07\/image-7-768x158.png 768w\" alt=\"\" width=\"701\" height=\"144\" \/><\/figure>\n<pre class=\"wp-block-code\"><\/pre>\n<h3 id=\"method-3-clearing-history-without-editing-the-bash-history-file\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Method_3_Clearing_history_without_editing_the_Bash_History_File\"><\/span>Method 3: Clearing history without editing the Bash History File<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>ertainly! The echo &gt; ~\/.bash_history command is a concise way to clear terminal history in Linux of the Bash history file. Here are detailed steps explaining how this command works:<\/p>\n<p>Open a Terminal:<br \/>\nOpen a <a href=\"https:\/\/chennaiwebhosting.in\/\" target=\"_blank\" rel=\"nofollow noopener\">terminal on your Linux system<\/a>. You can usually do this by searching for \u201cTerminal\u201d in your applications menu or by using a keyboard shortcut.<\/p>\n<p>Navigate to Home Directory:<br \/>\nEnsure that you are in your home directory. You can use the cd command to navigate to your home directory:<\/p>\n<pre class=\"wp-block-code\">cd ~<\/pre>\n<p>Execute the Command:<\/p>\n<p>Run the echo &gt; ~\/.bash_history command. This command uses the echo command to print an empty string (&gt;) and then redirects (&gt;) this output to the .bash_history file in your home directory:<\/p>\n<pre class=\"wp-block-code\">echo &amp;gt; ~\/.bash_history<\/pre>\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-264\" src=\"https:\/\/bestvpshosting.in\/articles\/wp-content\/uploads\/2024\/01\/image-8.png\" alt=\"\" width=\"850\" height=\"42\" \/><\/figure>\n<p>This essentially overwrites the contents of the ~\/.bash_history file with an empty string.<\/p>\n<p>Verify the Changes:<br \/>\nOptionally, you can use a text editor or the cat command to verify that the contents of the .bash_history file have been cleared. For example:<\/p>\n<pre class=\"wp-block-code\">cat ~\/.bash_history<\/pre>\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-265\" src=\"https:\/\/bestvpshosting.in\/articles\/wp-content\/uploads\/2024\/01\/image-9.png\" alt=\"\" width=\"865\" height=\"68\" \/><\/figure>\n<p>This should display nothing, indicating that the file is now empty.<\/p>\n<p>Optional: Save the Changes to History File:<\/p>\n<p>If you want to make sure the changes are saved, you can run the history -w command. This command writes the current command history to the history file: Clear terminal history in Linux<\/p>\n<p>This step is not strictly necessary, as the history file is automatically updated when you exit the terminal. However, running history -w ensures that the changes are immediately written to the file.<\/p>\n<p>By following these steps, you effectively clear the content of the Bash history file, preventing any previously executed commands from being stored in the history.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Clear terminal history in Linux can be done using various methods depending on your needs. Here are a few common ways: Method 1: Clear terminal history in Linux for Current Session Clear history command buffer: history -c This command clears the history for the current session. Clear terminal history in Linux Remove the history file: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1990","post","type-post","status-publish","format-standard","hentry","category-home"],"_links":{"self":[{"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/1990","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/comments?post=1990"}],"version-history":[{"count":8,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/1990\/revisions"}],"predecessor-version":[{"id":1998,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/1990\/revisions\/1998"}],"wp:attachment":[{"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/media?parent=1990"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/categories?post=1990"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chennaiwebhosting.in\/blog\/wp-json\/wp\/v2\/tags?post=1990"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}