My e-Notes about DataScience, Machine Learning, Python, Data Analytics, DataStage, DWH and ETL Concepts


Sunday, 3 January 2021

Linux History Command Tweak for better Administration

I use the Linux command “history” for various reasons like remembering previous commands, to see what was done on a server, to repeat commands and more. This article covers some useful tips I have accumulated to make the command more useful.

When examining the history command output I find it useful to have the date and time of when the command was executed so in my ~/.bashrc file I have:


Which provides output like:

$ history
1  2014-03-05 21:38 cd /etc
2  2014-03-05 21:38 ls
3  2014-03-05 21:38 ps -aux
4  2014-03-05 21:38 history

The default history file output as well as cache output is 500 lines I tend to increase this by double since I don’t like to lose my early history. Add this to your ~/.bashrc file:

export HISTSIZE=1000
export HISTFILESIZE=1000

*Note HISTSIZE controls the amount during the active session and HISTFILESIZE controls the size of the saved history file

Another annoying thing in your history file output can be duplication of commands in succession, to prevent these unnecessary duplicates I add the following to my ~/.bashrc file:

export HISTCONTROL=ignoredups

Sometimes you accidentally get ahead of yourself and mean to type sudo su – but instead enter your password at the prompt which then gets stored in your history cache. When this happens you can do the following command to remove that particular line in the history output.

$ history -d #
* Note where the # is the line number correlating to what you want to delete.

Other times you want to clear all your history for a particular shell session which you can do with the command:

$ history -c
If you want to get rid of all history permanently even from past sessions you can do the following:

$ :> ~/.bash_history
$ history -c

Hoping this post will help you to maintain the commands history.. Happy Learning !!

Like the below page to get update

No comments:

Post a comment


The postings on this site are my own and don't necessarily represent IBM's or other companies positions, strategies or opinions. All content provided on this blog is for informational purposes and knowledge sharing only.
The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of his information.