{"id":8192,"date":"2021-07-10T12:43:20","date_gmt":"2021-07-10T12:43:20","guid":{"rendered":"https:\/\/linuxways.net\/?p=8192"},"modified":"2021-07-10T12:43:20","modified_gmt":"2021-07-10T12:43:20","slug":"how-to-view-and-delete-terminal-history-in-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-view-and-delete-terminal-history-in-ubuntu-20-04\/","title":{"rendered":"How to View and Delete Terminal History in Ubuntu 20.04"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>The GNU history library keeps track of all the commands that run on the system in the ~\/.bash_history file by default. You can use this history to see and recall the past commands.<\/p>\n<p>In case you have security concerns, you can also clear this history. In this article, you will learn how you can view, manipulate and delete the terminal history in ubuntu.<\/p>\n<p>The commands in this tutorial are executed on the ubuntu 20.04 system.<\/p>\n<h2>How to View Terminal History in Ubuntu<\/h2>\n<h3>View all past commands in the History<\/h3>\n<p>You can display the previous history through the following command.<\/p>\n<pre>history<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"965\" height=\"697\" class=\"wp-image-8193\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-312.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-312.png 965w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-312-300x217.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-312-768x555.png 768w\" sizes=\"auto, (max-width: 965px) 100vw, 965px\" \/><\/p>\n<h3>View last \u2018n\u2019 number of commands in the History<\/h3>\n<p>You can also narrow down the history display to a specific number of lines. For example, to display the most recent 5 commands, run the following command.<\/p>\n<pre>history 5<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"164\" class=\"wp-image-8194\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-313.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-313.png 750w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-313-300x66.png 300w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/p>\n<h2>How to Delete Terminal History in Ubuntu<\/h2>\n<h3>Delete All Previous Commands in History<\/h3>\n<p>Run the following command to delete the current terminal history.<\/p>\n<pre>history -c<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"81\" class=\"wp-image-8195\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-314.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-314.png 750w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-314-300x32.png 300w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>You can notice that the above command will only delete the current terminal history. It will not affect the previous history that is stored in the history file. To overwrite the whole history file, you need to run the following command after running the \u201chistory -c\u201d command<\/p>\n<pre>history -w<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"110\" class=\"wp-image-8196\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-315.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-315.png 750w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-315-300x44.png 300w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>You can notice that the previous history has been deleted and overwritten in the following outcome.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"193\" class=\"wp-image-8197\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-316.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-316.png 750w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-316-300x77.png 300w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/p>\n<h3>Delete Single Command in History<\/h3>\n<p>You can delete specific lines in the history with the following command.<\/p>\n<pre>history -d &lt;&lt;line number&gt;&gt;<\/pre>\n<p><strong>Note: <\/strong> Insert the line number of the command you want to delete in the above command. You can see the line number displayed with the command while viewing the history.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"595\" class=\"wp-image-8198\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-317.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-317.png 800w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-317-300x223.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-317-768x571.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<h3>Delete History by Clearing ~\/.bash_history File<\/h3>\n<p>You can clear the entire terminal history with the following command.<\/p>\n<pre>ln -sf \/dev\/null ~\/.bash_history &amp;&amp; history -c<\/pre>\n<p>This command will link the \/dev\/null file to the history file and delete the records.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1244\" height=\"150\" class=\"wp-image-8199\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-318.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-318.png 1244w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-318-300x36.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-318-1024x123.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-318-768x93.png 768w\" sizes=\"auto, (max-width: 1244px) 100vw, 1244px\" \/><\/p>\n<h3>Delete History by Disabling the Terminal\/Bash History Logging<\/h3>\n<p>To turn off the logging of the terminal command, run the following commands.<\/p>\n<pre>sudo sh -c \"echo \"unset HISTFILE\" &gt;&gt; \/etc\/profile\"<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2009\" height=\"150\" class=\"wp-image-8200\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-319.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-319.png 2009w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-319-300x22.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-319-1024x76.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-319-768x57.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-319-1536x115.png 1536w\" sizes=\"auto, (max-width: 2009px) 100vw, 2009px\" \/><\/p>\n<p><strong>Note:<\/strong> you will need sudo\/root privilege to execute the above command.<\/p>\n<h3>Delete History by Editing the .bashrc File<\/h3>\n<p>You can change HISTSIZE and HISTFILESIZE variables in the .bashrc file to stop the history logging. To do that open a .bashrc file with the following command.<\/p>\n<pre>nano .bashrc<\/pre>\n<p>Now go to the lines mentioning HISTSIZE and HISTFILESIZE and change their value to zero. Press Ctrl+O and Ctrl+X to save changes and exit.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1230\" height=\"666\" class=\"wp-image-8201\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-320.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-320.png 1230w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-320-300x162.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-320-1024x554.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/07\/word-image-320-768x416.png 768w\" sizes=\"auto, (max-width: 1230px) 100vw, 1230px\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>Terminal history can be a benefit in case you want to revisit\/recall the past commands. But it can be a security risk because they can show system tools, configurations, and settings. You can view\/preserve or delete terminal history with the help of this article.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction The GNU history library keeps track of all the commands that run on the system in the ~\/.bash_history file by default. You can use this history to&hellip;<\/p>","protected":false},"author":1,"featured_media":8265,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[242,100],"class_list":["post-8192","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-linux-terminal","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/8192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=8192"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/8192\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/8265"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=8192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=8192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=8192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}