LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-25-2010, 05:59 AM   #1
sassy2010
LQ Newbie
 
Registered: Sep 2010
Posts: 5

Rep: Reputation: 0
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
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 09-25-2010, 06:14 AM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
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

Last edited by repo; 09-25-2010 at 06:21 AM.
 
Old 09-25-2010, 01:23 PM   #3
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,078

Rep: Reputation: 195Reputation: 195
Quote:
Originally Posted by repo View Post
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.
 
Old 09-25-2010, 03:15 PM   #4
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,027

Rep: Reputation: 69
cat /dev/null > ~/.bash_history

It's more fun hehe. It basically nulls out the file.
 
Old 09-25-2010, 03:19 PM   #5
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,078

Rep: Reputation: 195Reputation: 195
Code:
>~/.bash_history
It's shorter, but I'm not sure where it rates on the fun scale
 
Old 09-25-2010, 03:38 PM   #6
MrCode
Member
 
Registered: Aug 2009
Location: Oregon, USA
Distribution: Arch
Posts: 864
Blog Entries: 31

Rep: Reputation: 148Reputation: 148
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.
 
Old 09-25-2010, 03:44 PM   #7
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,078

Rep: Reputation: 195Reputation: 195
Quote:
Originally Posted by MrCode View Post
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.
 
Old 09-25-2010, 03:48 PM   #8
trist007
Senior Member
 
Registered: May 2008
Distribution: Slackware
Posts: 1,027

Rep: Reputation: 69
Why waste a good inode? I say leave the file and just wipe the contents. But yes both have the same result.
 
Old 09-25-2010, 04:11 PM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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.
 
2 members found this post helpful.
  


Reply

Tags
bash


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Fedora / .bash_history deeprlyeh Linux - Newbie 4 10-17-2007 11:55 PM
.bash_history question stakhous Linux - Newbie 1 05-24-2005 07:24 PM
.bash_history t3gah Linux - Software 2 05-05-2005 04:45 AM
bash_history linj Linux - Software 6 08-08-2003 11:13 AM
.bash_history gone togeno Linux - Security 3 06-30-2003 08:10 AM


All times are GMT -5. The time now is 10:33 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration