How to remove the entries in the "history" file from the command line

Posted on 2008-01-25
Medium Priority
Last Modified: 2010-04-21
Ou company allows several users access to the root user on our systems.  The problem I am havong is they are "experimenting" with commands that I have had to use to correct errors.  How can I either 1) prevent logging from specific users or 2) erase the history log.  I prefer option 1.
Question by:gordonmann
  • 2
  • 2
LVL 48

Expert Comment

ID: 20746806
Do the users login directly as root or do su -

To remove the bash history, just do

rm -f ~/.bash_history

You can have separate history files based on whatever criteria you come up with (eg: login name, terminal name, IP address etc).

For example, to have a separate history file based on the tty name, put the following in ~/.bash_profile

export HISTFILE=$HOME/.bash_history-$(tty|sed #/#-#g)

Author Comment

ID: 20746835
Everyone su to root

What if I just want a separate history file for myself BUT still want the ability to view what other users have done while logged in as root.
LVL 48

Accepted Solution

Tintin earned 2000 total points
ID: 20746874
In that case, put:

export HISTFILE=$HOME/.bash_history-$LOGNAME

in the root .bash_profile

then everyone will have their own history file based on their login name.  The bash history file is a simple text file, so you view it as per any other text file.

Author Closing Comment

ID: 31425143
Great help!!!

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Are you an IT professional responsible for a public computer (Class PC, Library PC, Hotels, Internet cafe, Kiosk, etc)? Do you have headaches maintaining them and removing all the junk left by users? Are they affected by viruses every day? Then brin…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question