Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Clear the terminal's command history UNIX
In case you've ever wanted to get rid of the command history in your terminal (pressing the Up Arrow Key will scroll through all the commands you've ever used), just delete the .bash_history file located inside your home folder (by using the command rm ~/.bash_history).

If you do that through the Terminal (since the file is invisible), the terminal will replace the file with the commands used in the current window (so if you open a new terminal window, use the command, then close/open a new window, the history will consist just of the command to remove the history file).
    •    
  • Currently 4.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[71,289 views]  

Clear the terminal's command history | 10 comments | Create New Account
Click here to return to the 'Clear the terminal's command history' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
tcsh version
Authored by: googoo on Mar 23, '04 10:06:53AM

If you use tcsh, ~/.tcsh_history is the history file.

-Mark



[ Reply to This | # ]
tcsh version
Authored by: vancenase on Mar 23, '04 10:17:56AM

i use tcsh, and i do not have a ~/.tcsh_history file ... ?



[ Reply to This | # ]
tcsh histfile variable
Authored by: sjk on Mar 23, '04 07:07:01PM

/usr/share/tcsh/examples/tcsh.defaults set the histfile variable to ~/.tcsh_history. Otherwise the default is ~/.history.

/usr/share/tcsh/examples/README explains how to use the tcsh example init files.



[ Reply to This | # ]
Notes on .bash/tcsh_history files
Authored by: aixccapt99 on Mar 23, '04 11:03:10AM

The existence of these history files is a good reason to never put your password on the command line -- always let the program prompt you for it.

Other details:
The history file doesn't keep every command you've ever typed; instead it keeps the most recent xxx (I believe the default in bash is 500, and you can change the value if you want).

Also, the file is updated only on a clean shell exit -- during your session, it's cached in memory -- so if you close a Terminal window with the prompt still active, your history file won't contain whatever commands you issued that session.



[ Reply to This | # ]
Clear the terminal's command history
Authored by: killbot8000 on Mar 23, '04 11:41:58AM
history -c
is an easier and more portable way of clearing the history.

[ Reply to This | # ]
Clear the terminal's command history
Authored by: Adam Schenker on Mar 23, '04 12:53:23PM
If you'd rather not have your history saved to a file at all, add the following line to your ~/.bash_profile:

unset HISTFILE

This way, your command history is limited to only those commands you used during the current session. More information and options can be found on the bash man page (man bash).

[ Reply to This | # ]

Clear the terminal's command history
Authored by: osxpounder on Mar 23, '04 05:38:12PM

I didn't have a .bash_profile, so I made one with only this line in it.

I don't notice any difference. I can quit & restart the Terminal, and still scroll back through weeks of my history.

I keep forgetting the way to check which shell I'm running, which might be the prob, for all I know. No, wait, I did a 'ps' and I see "-bash", so I'm using the same shell this hint's meant for.

Hmm.....

---
--
osxpounder



[ Reply to This | # ]
Clear the terminal's command history
Authored by: baddog on Mar 23, '04 06:22:49PM

To get it to work for you, you might need to log out and back in. bash_profile is only read at login time. Alternatively, you can put it in your ~/.bashrc file (read whenever a new shell is opened). It is redundant to set env variables everytime you start a new shell, but I do it often because it's convenient and guaranteed to work right away.

To make bash *erase* your history file every time you quit the shell, you should try this instead of unsetting HISTFILE:

export HISTFILESIZE=0



[ Reply to This | # ]
Clear the terminal's command history
Authored by: Adam Schenker on Mar 23, '04 07:36:02PM
Did you remove your old .bash_history file (rm ~/bash_history)? My suggestion will keep the history file from being created, but I don't think it will stop an already created history file from being used.

[ Reply to This | # ]
Clear the terminal's command history
Authored by: adamjacobmuller on Apr 15, '04 10:48:19PM

try
[code]history -c[/code]
mode compliant and somewhat more universal (it works on tcsh and bash)



[ Reply to This | # ]