{"id":8236,"date":"2019-11-14T12:03:14","date_gmt":"2019-11-14T17:03:14","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=8236"},"modified":"2021-12-08T10:42:13","modified_gmt":"2021-12-08T15:42:13","slug":"command-line-history","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/command-line-history\/","title":{"rendered":"How to Clear Bash Command Line History in Linux"},"content":{"rendered":"\n

There is a bash or Unix shell history that logs all the commands that the user runs. These records are the basis of the command line history that can be accessed by scrolling back and forth through those records by using the “up arrow<\/strong>” or “down arrow<\/strong>” keys.<\/p>\n\n\n\n

For very good reasons, it is possible to clear the entire command line history or delete selected entries.<\/p>\n\n\n\n

The primary reason for clearing the contents of the Bash history is security. One good example is where you pass a password as a parameter when running a command like:<\/p>\n\n\n\n

Using sshpass<\/strong> to set the password when copying files using SCP<\/strong> for example:<\/p>\n\n\n\n

$ sshpass -p "password" scp -r user@example.com:\/the\/remote\/path \/the\/local\/path<\/code><\/pre>\n\n\n\n

This example is used to copy a file using curl.<\/p>\n\n\n\n

$ curl --insecure --user username:password -T \/the\/sourcefile sftp:\/\/example.com\/path\/<\/code><\/pre>\n\n\n\n

This one is used to sign in to a MySQL<\/a> database.<\/p>\n\n\n\n

$ mysql -u root -p=password<\/code><\/pre>\n\n\n\n

Running any of those commands will end up having them being archived in the command line history. You would normally want to clear the history after running these types of commands to safeguard the passwords. This can be done by running:<\/p>\n\n\n\n

$ history -c<\/code><\/pre>\n\n\n\n

What if you want to retain the entire history but get rid of those individual commands? Well, you would first need to get the line history by running:<\/p>\n\n\n\n

$ history<\/code><\/pre>\n\n\n\n

This will display the entire bash command history. You then need to note the line number of the command you want to delete. When you are ready, type the following history command:<\/p>\n\n\n\n

$ history -d 435<\/code><\/pre>\n\n\n\n

Where 435<\/strong> is the line number of the command you want to get rid of. You would also want to take note that each user has only access to their own set of commands and not those typed in by other users. The root user can access other users’ bash commands.<\/p>\n\n\n\n

That is the easiest way to either clear the command line history or delete individual commands by line number.<\/p>\n","protected":false},"excerpt":{"rendered":"

There is a bash or Unix shell history that logs all the commands that the user runs. These records are the basis of the command line history that can be…<\/p>\n","protected":false},"author":1,"featured_media":8237,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,9,16],"tags":[313,354,431,433,471,523,526,572,604],"yoast_head":"\nHow to Clear the Bash Command Line History in Linux<\/title>\n<meta name=\"description\" content=\"This guide will show you how to clear the entire Bash command line history in or just a specific targetted commands in Linux\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/local.brightwhiz\/command-line-history\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Clear the Bash Command Line History in Linux\" \/>\n<meta property=\"og:description\" content=\"This guide will show you how to clear the entire Bash command line history in or just a specific targetted commands in Linux\" \/>\n<meta property=\"og:url\" content=\"http:\/\/local.brightwhiz\/command-line-history\/\" \/>\n<meta property=\"og:site_name\" content=\"Brightwhiz.com\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/brightwhiz\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-11-14T17:03:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-08T15:42:13+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/11\/command-line-history.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Michael Bright\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:site\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Michael Bright\" \/>\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\":\"Article\",\"@id\":\"http:\/\/local.brightwhiz\/command-line-history\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/command-line-history\/\"},\"author\":{\"name\":\"Michael Bright\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\"},\"headline\":\"How to Clear Bash Command Line History in Linux\",\"datePublished\":\"2019-11-14T17:03:14+00:00\",\"dateModified\":\"2021-12-08T15:42:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/command-line-history\/\"},\"wordCount\":309,\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/command-line-history\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/11\/command-line-history.jpg\",\"keywords\":[\"InfoSec\",\"Linux\",\"Operating Systems\",\"Optimization\",\"Programming\",\"Scripting\",\"Security\",\"Systems\",\"Unix\"],\"articleSection\":[\"Articles\",\"Guides\",\"How To\",\"Technology\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/local.brightwhiz\/command-line-history\/\",\"url\":\"http:\/\/local.brightwhiz\/command-line-history\/\",\"name\":\"How to Clear the Bash Command Line History in Linux\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/command-line-history\/#primaryimage\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/command-line-history\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/11\/command-line-history.jpg\",\"datePublished\":\"2019-11-14T17:03:14+00:00\",\"dateModified\":\"2021-12-08T15:42:13+00:00\",\"description\":\"This guide will show you how to clear the entire Bash command line history in or just a specific targetted commands in Linux\",\"breadcrumb\":{\"@id\":\"http:\/\/local.brightwhiz\/command-line-history\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/local.brightwhiz\/command-line-history\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/command-line-history\/#primaryimage\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/11\/command-line-history.jpg\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/11\/command-line-history.jpg\",\"width\":1200,\"height\":630,\"caption\":\"Command Line History\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/local.brightwhiz\/command-line-history\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/local.brightwhiz\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Clear Bash Command Line History in Linux\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/local.brightwhiz\/#website\",\"url\":\"http:\/\/local.brightwhiz\/\",\"name\":\"Brightwhiz.com\",\"description\":\"Best Tech guides, Tutorials, and News\",\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/local.brightwhiz\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/local.brightwhiz\/#organization\",\"name\":\"Brightwhiz\",\"url\":\"http:\/\/local.brightwhiz\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"width\":706,\"height\":135,\"caption\":\"Brightwhiz\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/brightwhiz\/\",\"https:\/\/twitter.com\/brightwhizmag\",\"https:\/\/instagram.com\/bright_whiz\/\",\"https:\/\/www.pinterest.com\/sobbayi\/\",\"https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\",\"name\":\"Michael Bright\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"caption\":\"Michael Bright\"},\"sameAs\":[\"https:\/\/sobbayi.com\"],\"url\":\"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Clear the Bash Command Line History in Linux","description":"This guide will show you how to clear the entire Bash command line history in or just a specific targetted commands in 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":"http:\/\/local.brightwhiz\/command-line-history\/","og_locale":"en_US","og_type":"article","og_title":"How to Clear the Bash Command Line History in Linux","og_description":"This guide will show you how to clear the entire Bash command line history in or just a specific targetted commands in Linux","og_url":"http:\/\/local.brightwhiz\/command-line-history\/","og_site_name":"Brightwhiz.com","article_publisher":"https:\/\/www.facebook.com\/brightwhiz\/","article_published_time":"2019-11-14T17:03:14+00:00","article_modified_time":"2021-12-08T15:42:13+00:00","og_image":[{"width":1200,"height":630,"url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/11\/command-line-history.jpg","type":"image\/jpeg"}],"author":"Michael Bright","twitter_card":"summary_large_image","twitter_creator":"@brightwhizmag","twitter_site":"@brightwhizmag","twitter_misc":{"Written by":"Michael Bright","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/local.brightwhiz\/command-line-history\/#article","isPartOf":{"@id":"http:\/\/local.brightwhiz\/command-line-history\/"},"author":{"name":"Michael Bright","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32"},"headline":"How to Clear Bash Command Line History in Linux","datePublished":"2019-11-14T17:03:14+00:00","dateModified":"2021-12-08T15:42:13+00:00","mainEntityOfPage":{"@id":"http:\/\/local.brightwhiz\/command-line-history\/"},"wordCount":309,"publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"image":{"@id":"http:\/\/local.brightwhiz\/command-line-history\/#primaryimage"},"thumbnailUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/11\/command-line-history.jpg","keywords":["InfoSec","Linux","Operating Systems","Optimization","Programming","Scripting","Security","Systems","Unix"],"articleSection":["Articles","Guides","How To","Technology"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/local.brightwhiz\/command-line-history\/","url":"http:\/\/local.brightwhiz\/command-line-history\/","name":"How to Clear the Bash Command Line History in Linux","isPartOf":{"@id":"http:\/\/local.brightwhiz\/#website"},"primaryImageOfPage":{"@id":"http:\/\/local.brightwhiz\/command-line-history\/#primaryimage"},"image":{"@id":"http:\/\/local.brightwhiz\/command-line-history\/#primaryimage"},"thumbnailUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/11\/command-line-history.jpg","datePublished":"2019-11-14T17:03:14+00:00","dateModified":"2021-12-08T15:42:13+00:00","description":"This guide will show you how to clear the entire Bash command line history in or just a specific targetted commands in Linux","breadcrumb":{"@id":"http:\/\/local.brightwhiz\/command-line-history\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/local.brightwhiz\/command-line-history\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/command-line-history\/#primaryimage","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/11\/command-line-history.jpg","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2019\/11\/command-line-history.jpg","width":1200,"height":630,"caption":"Command Line History"},{"@type":"BreadcrumbList","@id":"http:\/\/local.brightwhiz\/command-line-history\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/local.brightwhiz\/"},{"@type":"ListItem","position":2,"name":"How to Clear Bash Command Line History in Linux"}]},{"@type":"WebSite","@id":"http:\/\/local.brightwhiz\/#website","url":"http:\/\/local.brightwhiz\/","name":"Brightwhiz.com","description":"Best Tech guides, Tutorials, and News","publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/local.brightwhiz\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/local.brightwhiz\/#organization","name":"Brightwhiz","url":"http:\/\/local.brightwhiz\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","width":706,"height":135,"caption":"Brightwhiz"},"image":{"@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/brightwhiz\/","https:\/\/twitter.com\/brightwhizmag","https:\/\/instagram.com\/bright_whiz\/","https:\/\/www.pinterest.com\/sobbayi\/","https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ"]},{"@type":"Person","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32","name":"Michael Bright","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/","url":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","caption":"Michael Bright"},"sameAs":["https:\/\/sobbayi.com"],"url":"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/"}]}},"_links":{"self":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/8236"}],"collection":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/comments?post=8236"}],"version-history":[{"count":0,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/8236\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media\/8237"}],"wp:attachment":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media?parent=8236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/categories?post=8236"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/tags?post=8236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}