LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash_history (https://www.linuxquestions.org/questions/linux-newbie-8/bash_history-834404/)

sassy2010 09-25-2010 04:59 AM

bash_history
 
Hi all,

I used history -c command and pressed the up arrow to check if my history has been cleared. Well it has been cleared. Then i opened the bash_history file from my home directory and found that the commands that i typed before are still there. What am I doing wrong here? Please help

repo 09-25-2010 05:14 AM

Quote:

history -c
will only clear the history from the current session stored in RAM
To clear the history, you need to do
Code:

rm -rf ~/.bash_history

Kind regards

arizonagroovejet 09-25-2010 12:23 PM

Quote:

Originally Posted by repo (Post 4108508)
Code:

rm -rf ~/.bash_history

Using -rf means that a simple typo in the filename you want to delete could result in you deleting lots of things you didn't intend to. -rf should be used with caution, only when you have a lot of stuff to delete and are absolute positively sure that what you have typed will do exactly what you want.

If you just want to delete a single file use

Code:

rm ~/.bash_history
Personally I alias rm to 'rm -i' in my .bashrc so that I have to confirm deletions by default.

trist007 09-25-2010 02:15 PM

cat /dev/null > ~/.bash_history

It's more fun hehe. It basically nulls out the file.

arizonagroovejet 09-25-2010 02:19 PM

Code:

>~/.bash_history
It's shorter, but I'm not sure where it rates on the fun scale ;)

MrCode 09-25-2010 02:38 PM

Quote:

Originally Posted by trist007
Code:

cat /dev/null > ~/.bash_history

Quote:

Originally Posted by arizonagroovejet
Code:

>~/.bash_history

The thing about those is that the file is still *there*, it's just been reduced to a pointer/filename (i.e. it is now empty). rm actually removes the file entry from the filesystem.

arizonagroovejet 09-25-2010 02:44 PM

Quote:

Originally Posted by MrCode (Post 4108845)
The thing about those is that the file is still *there*, it's just been reduced to a pointer/filename (i.e. it is now empty). rm actually removes the file entry from the filesystem.

True. But making the file empty and deleting it both serve to wipe out the bash history.

trist007 09-25-2010 02:48 PM

Why waste a good inode? I say leave the file and just wipe the contents. But yes both have the same result.

colucix 09-25-2010 03:11 PM

history -c immediately followed by history -w should solve the issue without removing or redirecting anything. If you want to clear the history file every time you start a new shell session, a history -w statement in $HOME/.bashrc should do the trick.


All times are GMT -5. The time now is 02:41 PM.