Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating a script to run in the start up that says:

_cleanthehistory ()
/bin/echo "cleaning the history"
history -c

The deal here is that this does not work from the script, but if I run it from the command line works. Any ideas? Thanks in advance. Pablo.

share|improve this question
Is this the whole script or did you put that somewhere (e.g. in the bashrc)? If so, please post the whole script. If not, why did you write it inside a function instead of a plain /bin/echo "cleaning the history"; history -c. Also I think you're missing a semicolon in the version posted here. – con-f-use Mar 30 '12 at 18:02
Hi, yes this is a section of the script. – pma083 Mar 30 '12 at 18:06
As I said, there is a semicolon missing between the echo and the history command. Also if you do that from within a script you do it from the local scope of the script. Very much the same if you change a variable within a script it is not changed outside (in the terminal you ran the script in). – con-f-use Mar 30 '12 at 18:12
@con-f-use there are actually newlines there, they were just turned into spaces due to using the wrong formatting (for this site). – geirha Mar 30 '12 at 18:16
@geirha is right is because of the format of this site. – pma083 Mar 30 '12 at 18:21

As I said in my comment history -c just deletes the history of the current session, i.e. only the commands your script ran. To clear all data including old sessions you'll have to do something like

rm -f $HOME/.bash_history
share|improve this answer
thanks for your reply, i'll try deleting the .bash_history file. – pma083 Mar 30 '12 at 18:26
It didn't worked. :( – pma083 Mar 30 '12 at 18:30
cat /dev/null > ~/.bash_history :) Thanks to all for the help!. – pma083 Mar 30 '12 at 18:40

History is only enabled for interactive shells, not scripts. So in a script, history -c won't do much good. If you just want to empty your user's bash history during boot, as /tmp is emptied during boot, just truncate or delete ~/.bash_history.

echo "cleaning the history"
> /home/yourusername/.bash_history

This uses shell redirection without a command. It makes the shell just open the file for writing (truncating it if it already exists), then close it without writing anything to it (since there's no command to write anything to it).

On a side note, don't use absolute paths to commands in scripts. E.g. use echo, not /bin/echo.

update: Or if you don't want to save bash history at all, you could put something like HISTFILE=/dev/null in your ~/.bashrc.

share|improve this answer
Thanks @geirha I've tried that but didn't worked also, is really weird, in a debian server works like a charm, but not in the ubuntu . – pma083 Mar 30 '12 at 18:34
@pma083 How exactly are you running it at start up? – geirha Mar 30 '12 at 18:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.