LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-21-2009, 02:47 AM   #1
ashishag
LQ Newbie
 
Registered: Dec 2006
Posts: 6

Rep: Reputation: 0
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.
 
Old 03-21-2009, 02:52 AM   #2
iamback
LQ Newbie
 
Registered: Sep 2007
Posts: 24

Rep: Reputation: 15
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)
 
Old 03-21-2009, 02:09 PM   #3
prushik
Member
 
Registered: Mar 2009
Location: Pennsylvania
Distribution: gentoo
Posts: 372

Rep: Reputation: 29
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.
 
Old 03-22-2009, 06:08 AM   #4
almatic
Member
 
Registered: Mar 2007
Distribution: Debian
Posts: 547

Rep: Reputation: 67
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).
 
Old 03-22-2009, 07:16 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
...and depending on what "shouldn't be" means to the OP, also see the HISTIGNORE environment variable?
 
Old 08-01-2009, 02:14 AM   #6
BHABANIPRASADPATI
Member
 
Registered: Aug 2006
Location: ORISSA,INDIA
Distribution: Linux MINT
Posts: 34

Rep: Reputation: 15
Angry

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.
 
Old 05-02-2010, 03:39 AM   #7
ab1m
LQ Newbie
 
Registered: May 2010
Posts: 1

Rep: Reputation: 0
Quote:
Originally Posted by ashishag View Post
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:-)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash command history, page-up exodist Linux - General 5 04-17-2008 09:28 PM
LXer: CLI Magic: Using command history in the bash shell LXer Syndicated Linux News 0 07-03-2006 12:54 PM
F8 for command history in bash titanandrews Linux - General 7 10-15-2004 03:25 PM
Wiping bash command history? skewer Linux - General 3 07-30-2003 02:33 PM
bash command history problem crabboy Slackware 1 10-17-2002 07:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:34 AM.

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