How to clear history in Linux


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to clear history in Linux
# 1  
Old 12-15-2010
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
# 2  
Old 12-15-2010
SmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilie

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.
R0H0N
# 3  
Old 12-15-2010
The posting implies that the user is using bash. In this instance the history is usually kept in $HOME/.bash_history
# 4  
Old 12-15-2010
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
# 5  
Old 12-15-2010
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.
# 6  
Old 12-15-2010
Code:
rm -f ~/.bash_history
history -c
exit

# 7  
Old 12-15-2010
Great, it worked !! histort -c option itself worked without removing bash history file. :-)

Thanks a lot to all of you.:-)
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Clear standard input buffer for C program in Linux

Hello friends! i am writing a code in which i take inputs (numbers) from user and count the total number of positive, negative and zeros entered. I need to clear my standard input buffer before scanf() command. My compiler is completely ignoring the fflush(stdin) command. its not even showing any... (1 Reply)
Discussion started by: Abhishek_kumar
1 Replies

2. UNIX for Dummies Questions & Answers

[Solved] How to clear "history" command entries??

As in the title, how to clear the history entries? For eg: if i enter history, series of linux commands getting displayed from day 1. I need to clear those entries and want linux commands to be stored freshly. Thanks in advance (6 Replies)
Discussion started by: karthick nath
6 Replies

3. Shell Programming and Scripting

Clear history in ksh

Hi Am using ksh shell I need to remove history of commands used.. I tried # rm .vi_history # touch .vi_history # chmod 600 .vi_history This didnt work.. I tried also # rm .sh_history # touch .sh_history # chmod 600 .sh_history (5 Replies)
Discussion started by: Priya Amaresh
5 Replies

4. Shell Programming and Scripting

how to clear history in ksh?

I want to clear the history so that no one should be able to see what commands I gave in the AIX OS level. I tried using history -c , ~/.sh_history, but they aren't working :wall: Please tell me the command in ksh which can clear all the previous history? (4 Replies)
Discussion started by: lg123
4 Replies

5. Linux

clear in Linux ksh

Clear in Linux #!/usr/bin/ksh am using clear in the script, but it is not working, it gives an error as follows, 'xterm': unknown terminal type. please help out.:confused: ---------- Post updated at 01:19 PM ---------- Previous update was at 12:01 PM ---------- if then ... (2 Replies)
Discussion started by: pradebban
2 Replies

6. Shell Programming and Scripting

How to clear history logs of all terminal sessions

Hi, I would normally clear off the history entries from a terminal by using the following commands: > ~/.bash_history history -c But this will remove the entries of that particular session only. How to prune all the entries of all login sessions for a particular user in a system? N.B:... (3 Replies)
Discussion started by: royalibrahim
3 Replies

7. Linux

History of executed command in Linux

Hi All, Is there a way to check command executed by users in Linux for a specific date? I know we can use history, but it doesn't shows yesterday's executed commands. rgds, (3 Replies)
Discussion started by: ronny_nch
3 Replies

8. Solaris

how to clear command history

hi Any one can help me. I am using Sun_Solaris. The command history set to 100 at .cshrc. I am unable to clear the command histoy. In Linux it is very easy by giving command history -c I could not find any such type command to clear the history. Is there any such type of command for solaris.... (3 Replies)
Discussion started by: prabir
3 Replies

9. UNIX for Dummies Questions & Answers

how to clear history

Hi... i have one doubt pls... 1)can we clear the command line history in UNIX for a paricular login(scadm/root)if so how?. 2) can we see the time at which command executed. history is showing like : 100 display 101 lock 102 exit (7 Replies)
Discussion started by: gincemathew
7 Replies

10. UNIX for Advanced & Expert Users

clear passwd history without ...

how do I clear passwd history of a user without compromising the audit trail for security? in a nutshell, user abc wants to re-use his passwd ( he is not savvy with computers ) (4 Replies)
Discussion started by: A Stewart
4 Replies
Login or Register to Ask a Question