Linux Tips: take control of your bash_history - MDLog:/sysadmin
I spend most of my time working in front of a black and white terminal of remote SSH connections to various servers. This means that I use bash (as my preferred shell) most of the day. And bash history is a very important feature of bash that saves me much time by recalling previous commands I have typed. Here are some tricks on how you can optimize with some simple configurations settings the usage your bash history.
1. Don't save duplicates: This is my favorite…
HISTCONTROL=ignoreboth
this causes any lines matching the previous history entry not to be saved. Other options for HISTCONTROL: ignorespace, lines which begin with a space character are not saved in the history list; erasedups causes all previous lines matching the current line to be removed from the history list before that line is saved.
2. Size of the history: HISTSIZE: The number of commands to remember in the command history. The default value is 500.
HISTSIZE=500
You can set this to 0 and disable the usage of the history file.
3. Others: HISTFILE: The name of the file in which command history is saved. The default value is ~/.bash_history. HISTIGNORE: A colon-separated list of patterns used to decide which command lines should be saved on the history list.
How do you set these options? Either export them in your environment in your personal bash configuration file (~/.bashrc) or in the global bash configuration file (/etc/bash.bashrc). The name of the configuration files can depend from your Linux distribution and bash version (the ones included are from Debian Linux), but you can always see your particular options using man bash. So, you can add in your configuration files the parameters you want like this:
Read full article from Linux Tips: take control of your bash_history - MDLog:/sysadmin
No comments:
Post a Comment