{"id":3576,"date":"2010-10-09T14:07:15","date_gmt":"2010-10-09T18:07:15","guid":{"rendered":"http:\/\/g33kinfo.com\/info\/?p=3576"},"modified":"2010-10-09T14:07:15","modified_gmt":"2010-10-09T18:07:15","slug":"delete-last-command-from-bash-history","status":"publish","type":"post","link":"https:\/\/g33kinfo.com\/info\/delete-last-command-from-bash-history\/","title":{"rendered":"Delete last command from bash history"},"content":{"rendered":"<p>From <a href=\"http:\/\/thoughtsbyclayg.blogspot.com\/2008\/02\/how-to-delete-last-command-from-bash.html\" target=\"_blank\" rel=\"noopener noreferrer\">thoughtsbyclayg.blogspot.com<\/a><\/p>\n<p>how to delete last command from bash history<br \/>\nIf you have ever typed something into a command prompt that you wished you hadn&#8217;t &#8211; you may find it useful to know that you can delete it from ~\/.bash_history very easily.<\/p>\n<p>The command:<br \/>\n<code>history -d offset<\/code><br \/>\nwill delete the history entry at position offset.<br \/>\n<code><br \/>\n# history<br \/>\n1 cd<br \/>\n2 history<br \/>\n3 ls -alhF<br \/>\n4 history<br \/>\n5 wget username:password@private.ftp.com\/secret\/file.tar.gz<br \/>\n6 history<br \/>\n<\/code><br \/>\nso to delete the wget command (which contains a password) &#8211; just use:<br \/>\n<code>history -d 5<\/p>\n<p># history -d 5<br \/>\n# history<br \/>\n1 cd<br \/>\n2 history<br \/>\n3 ls -alhF<br \/>\n4 history<br \/>\n5 history<br \/>\n6 history -d 5<br \/>\n7 history<br \/>\n<\/code><br \/>\nBut suppose you KNOW you&#8217;re about to enter a command you don&#8217;t want to go into history. It&#8217;d be nice if you could just tack a little &#8220;hideme&#8221; modifer onto the front or tail of your command and be done with it. Unfortunately from what I&#8217;ve been able to google there is no such feature built into history or bash.<\/p>\n<p>Naturally I made one.<br \/>\n<code><br \/>\nTMP=$(history | tail -1 | awk '{print $1}') && history -d $TMP && \\<br \/>\npaste_in_shell_and_replace_this_with_whatever_you_want_to_hide<br \/>\n<\/code><br \/>\nAnd naturally someone smarter than me came along and found a better way to do it &#8211; THANKFULLY they posted a comment here to help us out (thanks Mitch!):<br \/>\n<code><br \/>\nhistory -d $((HISTCMD-1)) && \\<br \/>\npaste_in_shell_and_replace_this_with_whatever_you_want_to_hide<br \/>\n<\/code><br \/>\nRather than holding down backspace, you may find it useful to know that in bash Ctrl-W will delete from the cursor to the beginning of the previous word.<\/p>\n<p>What I don&#8217;t get, is that according man bash HISTCMD should be the CURRENT history number:<br \/>\nHISTCMD<br \/>\nThe history number, or index in the history list, of the current command.<\/p>\n<p>and yet in ALL my tests $HISTCMD is the &#8220;index in the history list, of the current command&#8221; +1<\/p>\n<p>But it can still lead to two two useful aliases:<br \/>\n<code><br \/>\nalias hideme='history -d $((HISTCMD-1))'<br \/>\nalias hideprev='history -d $((HISTCMD-2)) && history -d $((HISTCMD-1))'<br \/>\n<\/code><br \/>\nDig the sneaky:<br \/>\n<code><br \/>\n# history<br \/>\n1 cd<br \/>\n2 history<br \/>\n3 ls -alhF<br \/>\n4 history<br \/>\n5 history<br \/>\n6 history -d 5<br \/>\n7 history<br \/>\n8 vi .bashrc<br \/>\n9 history<br \/>\n# echo password && hideme<br \/>\npassword<br \/>\n# echo password<br \/>\npassword<br \/>\n# hideprev<br \/>\n# history<br \/>\n1 cd<br \/>\n2 history<br \/>\n3 ls -alhF<br \/>\n4 history<br \/>\n5 history<br \/>\n6 history -d 5<br \/>\n7 history<br \/>\n8 vi .bashrc<br \/>\n9 history<br \/>\n10 history<br \/>\n<\/code><\/p>\n<p>I know the blog&#8217;s kinda been on Linux kick lately &#8211; some of that is coming from the new job &#8211; I&#8217;m using Linux more. But, I&#8217;ve been working on a little project in Eclipse &#8211; Java\/SWT &#8211; and I&#8217;m getting to a point where I may have some useful learnings to post coming out of that. Or maybe not&#8230;<\/p>\n<p>Internet Tablet, and all my xbox&#8217;s are running fine&#8230;<\/p>\n<p>I&#8217;d like to throw out some props to Ivie for sending me an email about one of my posts that she read. I try to post stuff that I myself have trouble finding out there on the interwebz &#8211; so it&#8217;s always nice to hear from someone that finds it useful &#8211; thanks Ivie!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>From thoughtsbyclayg.blogspot.com how to delete last command from bash history If you have ever typed something into a command prompt that you wished you hadn&#8217;t &#8211; you may find it useful to know that you can delete it from ~\/.bash_history very easily. The command: history -d offset will delete the history entry at position offset&#8230;. <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/g33kinfo.com\/info\/delete-last-command-from-bash-history\/\">Read More<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-3576","post","type-post","status-publish","format-standard","hentry","category-info"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Delete last command from bash history - Linux Shtuff<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/g33kinfo.com\/info\/delete-last-command-from-bash-history\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Delete last command from bash history - Linux Shtuff\" \/>\n<meta property=\"og:description\" content=\"From thoughtsbyclayg.blogspot.com how to delete last command from bash history If you have ever typed something into a command prompt that you wished you hadn&#8217;t &#8211; you may find it useful to know that you can delete it from ~\/.bash_history very easily. The command: history -d offset will delete the history entry at position offset.... Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/g33kinfo.com\/info\/delete-last-command-from-bash-history\/\" \/>\n<meta property=\"og:site_name\" content=\"Linux Shtuff\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:author\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:published_time\" content=\"2010-10-09T18:07:15+00:00\" \/>\n<meta name=\"author\" content=\"g33kadmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/drsinger1111\" \/>\n<meta name=\"twitter:site\" content=\"@drsinger1111\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/delete-last-command-from-bash-history\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/delete-last-command-from-bash-history\\\/\"},\"author\":{\"name\":\"g33kadmin\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"headline\":\"Delete last command from bash history\",\"datePublished\":\"2010-10-09T18:07:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/delete-last-command-from-bash-history\\\/\"},\"wordCount\":393,\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"articleSection\":[\"General Info\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/delete-last-command-from-bash-history\\\/\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/delete-last-command-from-bash-history\\\/\",\"name\":\"Delete last command from bash history - Linux Shtuff\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\"},\"datePublished\":\"2010-10-09T18:07:15+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/delete-last-command-from-bash-history\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/g33kinfo.com\\\/info\\\/delete-last-command-from-bash-history\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/delete-last-command-from-bash-history\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Delete last command from bash history\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\",\"name\":\"Linux Shtuff\",\"description\":\"Because I have CRS Syndrome...\",\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\",\"name\":\"g33kadmin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"contentUrl\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"width\":512,\"height\":512,\"caption\":\"g33kadmin\"},\"logo\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\"},\"description\":\"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\\\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....\",\"sameAs\":[\"https:\\\/\\\/thelinuxreport.com\",\"https:\\\/\\\/fb.me\\\/g33kinf0\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/drsinger1111\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Delete last command from bash history - Linux Shtuff","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:\/\/g33kinfo.com\/info\/delete-last-command-from-bash-history\/","og_locale":"en_US","og_type":"article","og_title":"Delete last command from bash history - Linux Shtuff","og_description":"From thoughtsbyclayg.blogspot.com how to delete last command from bash history If you have ever typed something into a command prompt that you wished you hadn&#8217;t &#8211; you may find it useful to know that you can delete it from ~\/.bash_history very easily. The command: history -d offset will delete the history entry at position offset.... Read More","og_url":"https:\/\/g33kinfo.com\/info\/delete-last-command-from-bash-history\/","og_site_name":"Linux Shtuff","article_publisher":"https:\/\/fb.me\/g33kinf0","article_author":"https:\/\/fb.me\/g33kinf0","article_published_time":"2010-10-09T18:07:15+00:00","author":"g33kadmin","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/drsinger1111","twitter_site":"@drsinger1111","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/g33kinfo.com\/info\/delete-last-command-from-bash-history\/#article","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/delete-last-command-from-bash-history\/"},"author":{"name":"g33kadmin","@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"headline":"Delete last command from bash history","datePublished":"2010-10-09T18:07:15+00:00","mainEntityOfPage":{"@id":"https:\/\/g33kinfo.com\/info\/delete-last-command-from-bash-history\/"},"wordCount":393,"publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"articleSection":["General Info"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/g33kinfo.com\/info\/delete-last-command-from-bash-history\/","url":"https:\/\/g33kinfo.com\/info\/delete-last-command-from-bash-history\/","name":"Delete last command from bash history - Linux Shtuff","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/#website"},"datePublished":"2010-10-09T18:07:15+00:00","breadcrumb":{"@id":"https:\/\/g33kinfo.com\/info\/delete-last-command-from-bash-history\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/g33kinfo.com\/info\/delete-last-command-from-bash-history\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/g33kinfo.com\/info\/delete-last-command-from-bash-history\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/g33kinfo.com\/info\/"},{"@type":"ListItem","position":2,"name":"Delete last command from bash history"}]},{"@type":"WebSite","@id":"https:\/\/g33kinfo.com\/info\/#website","url":"https:\/\/g33kinfo.com\/info\/","name":"Linux Shtuff","description":"Because I have CRS Syndrome...","publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/g33kinfo.com\/info\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547","name":"g33kadmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","url":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","contentUrl":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","width":512,"height":512,"caption":"g33kadmin"},"logo":{"@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif"},"description":"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....","sameAs":["https:\/\/thelinuxreport.com","https:\/\/fb.me\/g33kinf0","https:\/\/x.com\/https:\/\/twitter.com\/drsinger1111"]}]}},"_links":{"self":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/3576","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/comments?post=3576"}],"version-history":[{"count":0,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/3576\/revisions"}],"wp:attachment":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/media?parent=3576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/categories?post=3576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/tags?post=3576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}