0

I am writing an script to dump my history log into another file "myhistory.log", and then clear that history. I have written the following set of commands:

date >> myhistory.log

history >> myhistory.log

history -c

Everything goes well except that the previous history is not cleared. I have tried the following variations:

\history -c

and

CLRH="history -c"
exec $CLRH

What I am missing probably??

Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407

1 Answers1

3

By default, for bash, the command history are stored in ~/.bash_history file.

As an alternative you can do this:

#!/bin/bash
date >> ~/myhistory.log
cat ~/.bash_history >> ~/myhistory.log
echo -n "" > ~/.bash_history

This will append to ~/myhistory.log (if the file is already there, else create a new file and write to it) the date when the script was run, dump your history, and clear the ~/.bash_history file.

rusty
  • 16,917