banner
Previous Page
PCLinuxOS Magazine
PCLinuxOS
Article List
Disclaimer
Next Page

Clear YOUR History ... Completely


by Paul Arnote (parnote)

Anyone who has spent any time at all on the Linux command line in a terminal session either knows about or has heard of the history command. With today's current fears about privacy (or more precisely, the lack thereof), you might want to erase your command line "tracks" by erasing your command line history.

Since the history command is part of bash's built in commands, there is a man page entry for the command, extracted from the bash_builtins man page.

history [n]
history -c
history -d offset
history -anrw [filename]
history -p arg [arg ...]
history -s arg [arg ...]

With no options, display the command history list with line numbers. Lines listed with a * have been modified. An argument of n lists only the last n lines. If the shell variable HISTTIMEFORMAT is set and not null, it is used as a format string for strftime(3) to display the time stamp associated with each displayed history entry. No intervening blank is printed between the formatted time stamp and the history line. If filename is supplied, it is used as the name of the history file; if not, the value of HISTFILE is used.

Options, if supplied, have the following meanings:

-c Clear the history list by deleting all the entries.
-d offset; Delete the history entry at position offset.
-a Append the ``new'' history lines (history lines entered since the beginning of the current bash session) to the history file.
-n Read the history lines not already read from the history file into the current history list. These are lines appended to the history file since the beginning of the current bash session.
-r Read the contents of the history file and append them to the current history list.
-w Write the current history list to the history file, overwriting the history file's contents.
-p Perform history substitution on the following args and display the result on the standard output. Does not store the results in the history list. Each arg must be quoted to disable normal history expansion.
-s Store the args in the history list as a single entry. The last command in the history list is removed before the args are added.

The bash history is stored in the /home directory for each user. It is a hidden plain text file, called .bash_history. Note the "." before the filename, which causes the file to remain hidden, unless you've selected to show hidden files.

The history command does have an option that usually will clear your bash history. That command is history -c. If all you ever have open at any one time is ONE -- and only one -- terminal window, this command works very well. But, if you have multiple terminal windows open at the same time, this command doesn't work nearly as well. It will leave items in your bash history. Plus, with almost all Linux desktops supporting multiple desktops, it's very easy to forget that you opened a terminal window on another desktop.

So, we need a more certain way to delete our bash history. A way that won't let us down, even if we have multiple terminal windows open. Of all the things that Linux users find appealing about Linux, one of those is that there always seems to be more than one way to accomplish the tasks we need to complete.

If you want to be certain that ALL of your bash history has been deleted, thus completely erasing your command line "tracks," regardless of how many terminal windows you have open, you should enter the following command:

cat /dev/null > ~/.bash_history

This command will completely empty out the contents of your .bash_history file, but still leave the file in place.

You can automate this task by setting it up as a cron job to be ran on a schedule you decide. The cron job must be setup for each user's /home directory that you want to clear the bash history for.

Let's say that our assistant editor, Meemaw, wanted to delete her bash history once a week, every week, at 8 a.m. every Sunday. She would need to enter the following command:

crontab -e 0 8 * * 0 cat dev/null > ~/.bash_history

Now, Meemaw's computer will automatically clear out her bash history, on the schedule she chooses. This is, in all practicality, a "set-it-and-forget-it" solution.


Summary

Is clearing out your bash history bordering on paranoid? Maybe. But there are some users who go to such lengths as to hide even their bash history, so no one else can come along and track what tasks they were performing on their computer. And frankly, it really isn't anyone else's business what any other user is using their computer for, especially the three and four letter government agencies who like to snoop just because they can.

Plus, if you are a command line commando and perform a lot of tasks from the command line, the information in your bash history can be quite incriminating and revealing about your actions on the computer. Especially in that case, it might be a really good idea to minimize or eliminate your command line "tracks" periodically.

If you've never peered into the .bash_history file, you might be a bit surprised. Entire commands, complete with file names, are preserved. In some instances, those file names might reveal more than you realize, and more than you would ordinarily be willing to reveal.

An ounce of prevention provides a pound of cure.



Previous Page              Top              Next Page