Welcome to the most active Linux Forum on the web.
Go Back > Blogs > linux-related notes
User Name


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Ignoring lines starting with space, and other patterns in bash_history

Posted 08-25-2013 at 11:18 PM by the dsc
Updated 08-25-2013 at 11:22 PM by the dsc

It may be a little bit unsafe to have "rm something" commands in your bash history, if you also have the history easily accessible through up and down keys.

The following line will make bash history ignore "rm" and "shutdown":

export HISTIGNORE="&:rm *:shutdown *"
I don't know the syntax, but it works.

Some people have add there an expression to make bash's history ignore any line starting with a space, it would be ":[\t]*" at the end of that string, but I've found that it was also making the history ignore anything starting with "t" (perhaps because I had missed the space between "[" abd "\", like I just did). There's a better way to do it:

Originally Posted by Hnat Kubov
I know this post is too old, but since it shows up in google search on "histignore", I have to add, that there's more-- em, 'built-in' way of ignoring commands that start with " ". So, instead of adding "[ \t]*" to HISTIGNORE, you can use HISTCONTROL=ignorespace. But actually I don't know if it makes any difference. Just makes your .bashrc more readable.
"HISTCONTROL=ignoreboth" will ignore both lines starting with spaces, and duplicate lines.
Posted in Uncategorized
Views 728 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 05:36 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration