LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Bash history delete command from bash itself (http://www.linuxquestions.org/questions/linux-software-2/bash-history-delete-command-from-bash-itself-713309/)

ashishag 03-21-2009 02:47 AM

Bash history delete command from bash itself
 
Hi,
I use bash history extensively and there are times when I find that a command is there in bash history when it shouldn't be. Rather than going to .bash_history and delete the line corresponding to the command, is there a way, to delete that command from bash itself. For example, by doing Ctrl-P repeatedly, I move to that command, and then typing Ctrl-u deletes it. But then this remain only for the current session and the change is not permanent, that is, the command hasn't been deleted from the file actually, but only from the history loaded by bash in the memory. I hope I've made myself clear.
I'll be really grateful if someone could answer this question.

iamback 03-21-2009 02:52 AM

I hope that the regulators quash the deal and stop IBM from taking over SUN as a whole, otherwise IBM will once again become the evil empire. In fact the deal shouldn't be allowed at all. Because for... (0 views, 1 replies)

prushik 03-21-2009 02:09 PM

You should just write a bash shell script that will remove it from the .bash_history file. Then put the script in /usr/bin. That way whenever you need to remove something, you just enter the name of your script.

almatic 03-22-2009 06:08 AM

The command "history" will show you the current history list, "history -d xxx" will delete a specified line.
In order to make the changes permanent type "history -w". Though I don't know if this really deletes the line from the file, I think it rather appends the current (modified) history list to the file (which has the same optical effect, but the deleted commands are still in the file somewhere).

unSpawn 03-22-2009 07:16 AM

...and depending on what "shouldn't be" means to the OP, also see the HISTIGNORE environment variable?

BHABANIPRASADPATI 08-01-2009 02:14 AM

can any one tell me where exactly the bash_history file resides... !!

I tried to delete the .bash_history, the file got deleted too. But when I gave history in the bash prompt again its showing the history.

ab1m 05-02-2010 03:39 AM

Quote:

Originally Posted by ashishag (Post 3482860)
Hi,
I use bash history extensively and there are times when I find that a command is there in bash history when it shouldn't be. Rather than going to .bash_history and delete the line corresponding to the command, is there a way, to delete that command from bash itself. For example, by doing Ctrl-P repeatedly, I move to that command, and then typing Ctrl-u deletes it. But then this remain only for the current session and the change is not permanent, that is, the command hasn't been deleted from the file actually, but only from the history loaded by bash in the memory. I hope I've made myself clear.
I'll be really grateful if someone could answer this question.

Your history is in you .bash_history file! From a terminal find your home folder
(mine is /home/mahdiy). If you type pwd you will know what folder you are in.

If you see /home/xxxx then type ls -a then you will see all of your folders. You will see .bash_history in that list!

Then use a text editor like vi. You would type if using vi: vi .bash_history
I used joe instead. I like joe because you (I rather) can move around easier than I can with vi. In joe you can also tell it to jump to line so an so.

So I wrote down the lines I wanted to remove from my history. Went in to a terminal, typed pwd to make curtain I was where I wanted to be. You can also type ls -a so you see your .bash_history listed your home/xxx directory.

Then type joe (or what ever text editor your are using) .bash_history and you are in.

find the lines you want to remove and remove them.. Save and exit and your done.

There is a joe tutorial on line. You can fool around with the tutorial for a while before you make the plunge:-)

I hope that help:-)


All times are GMT -5. The time now is 05:38 PM.