How to clear history in Linux

Hello All, Good Morning.

I am trying to erase history list in my linux box, but my below command is failing. What is the actual way to clear it?

> history clear
-bash: history: clear: numeric argument required

Also when I run my commands in my command prompt, my team lead can see my command list as he has the root access. Any alternate way to issue commands so that nobody can get my commands?

Thanks,
Naresh

:D:D:D:D:D:D:D:D

I also had a same problem long time back. I was using UNIX-HP and I found that all entries are stored in .sh_history(hidden file) in my home directory. So, I just made it empty and I was done. U can also try this.

The posting implies that the user is using bash. In this instance the history is usually kept in $HOME/.bash_history

Hi Rohan,

Thanks for your reply.

I am using bash shell and my historyfile is set to .bash_history. but surprisingly when I am trying to view this file, it's empty. but again history 10 command is giving me some output. How it's possible? That means history data is not getting written into .bash_history. What you think ?

echo $SHELL
/bin/bash

echo $HISTFILE
/home/naresh/.bash_history

ls -l /home/naresh/.bash_history
-rw------- 1 naresh users 0 2010-12-14 9:49 /home/naresh/.bash_history

history 10
24 history -10
25 history -l
26 history 1
27 history 10
28 history 100
29 cat /home/naresh/.bash_history
30 ls -l /naresh/.bash_history
31 echo $HISTFILE
32 echo $SHELL
33 history 10

Thanks,
Naresh

Bash keeps it's history internally until it exits. This is why your .bash_history can be empty while you see old commands. This is also the reason why, when closing multiple instances of bash (eg. terminal sessions), only the commands from the last closed session can be found again.

To completely clear, you'll have to remove .bash_history without running bash.

rm -f ~/.bash_history
history -c
exit

Great, it worked !! histort -c option itself worked without removing bash history file. :slight_smile:

Thanks a lot to all of you.:slight_smile:

Why remove bash_history in first place. It good to have history :slight_smile:
simply

cp /dev/null ~/.bash_history 

Your file is empty and + you have

history -c 

if you really want to get rid of things.