There are some settings that are very useful if you work on the terminal a lot. Many of the cool ones are not enabled by default – this is a small list of the configuration settings that I use to make my terminal usage more productive.
This is part 3 of the Customizing the Terminal series. Already published posts in this series are…
1. Case Correction
I like to title case my folders and files’ names. The folders in my home are ‘Scripts’, ‘Documents’, ‘Temp’ etc. The first character is in upper case. But when I work on the command line, I don’t always remember to uppercase the first character when trying to cd into a folder. Consequently, the tabbing will not work. Fortunately, there is an option that auto corrects the case for you. Just open a terminal and type in this command…
shopt -s nocaseglob
Other useful shopt option are…
- cdspell
- Corrects typos in your file/directory name.
- histappend
- Makes sure that histories in multiple simultaneous shells don’t overwrite each other.
2. Select Which Commands to Store in History
By default, all commands you type in are stored in the history. You can pick and chose the commands you want to store by putting the option…
export HISTCONTROL=ignorespace
in your ~/.bash_profile
file. This will make sure that bash don’t store any command beginning with the space character. So if you want bash to forget that you typed in ‘ls’, just type in ‘ ls'(<space>ls).
3. Don’t Store Duplicate Commands in your History
As I said earlier, all commands you type are stored – even the duplicate ones. You can prevent this by putting this text in your .bash_profile
file…
export HISTCONTROL=ignoredups
If you want to ignore spaced commands and want to prevent storing of duplicate commands, use the option…
export HISTCONTROL=ignoreboth
4. Auto-complete Command from History
Picture this – you type in ‘ssh’ and press the ‘Page Up’ key – and bash automatically fetches the last command that starts with ssh – and completes the command for you. Well, its possible – add the following line in your ‘.bash_profile’ file…
export INPUTRC=$HOME/.inputrc
Now, create a file called .inputrc
in your home and enter this into it…
#Page up/page down
"\e[5~": history-search-backward
"\e[6~": history-search-forward
Yes, I am aware of the up Ctrl+R trick – that comes in the next post.
5. Infinite History
You can increase or decrease the size of the history by adding this line in the .bash_profile
file…
export HISTSIZE=500
export HISTFILESIZE=500
This will limit the commands to be stored in the history to 500. If you want to remove the limit use these lines…
unset HISTSIZE
unset HISTFILESIZE
There is a good chance that this will make your history file quite huge – use with care.
Please share your configuration settings for bash in the comments.
Excellent Post! Way to go. Finds its way in my config files 🙂
Great post.
I tried the case correction and cdspell feature. But it is not working 🙁 Using Debian Lenny.
some aliases I have in ~/.bashrc I use regularly:
alias l=’ls -la’
alias lt=’ls -l –sort=time -r’
alias i=’sudo apt-get install’
alias r=’sudo apt-get remove’
# This is my File ~/sh/bash_aliases_project.sh
# Use with caution!!!
#########################################
#!/bin/bash
################################################################################
## Simple Aliases ##
################################################################################
# Relative Jumps
alias ..=’cd ..’
alias …=’cd ../..’
alias ….=’cd ../../..’
alias …..=’cd ../../../..’
# enable color support of ls and also add handy aliases
## @TODO The Color Support adds binary characters
if [ -x /usr/bin/dircolors ]; then
eval “`dircolors -b`”
alias ls=’ls -lah –color=auto’
alias dir=’dir –color=auto’
alias vdir=’vdir –color=auto’
alias grep=’grep –color=auto’
alias fgrep=’fgrep –color=auto’
alias egrep=’egrep –color=auto’
else
alias ls=’ls -lah’
fi
alias dir=’ls –color=auto –format=vertical’
alias vdir=’ls –color=auto –format=long’
alias mkdir=’mkdir -p’
alias cheat=’less ~/cheat’
alias bjdbcheck=”mysqlcheck –all-databases –all-in-1 –repair”
# some more ls aliases
alias ll=’ls -l’
alias la=’ls -lahL’
alias l=’ls -CF’
alias home=’cd ~/’
alias h=’cd ~/’
alias cdp=’cd $p’
alias f=”find . |grep ”
alias ggl=’ping google.com -c 5′
alias nwc=”sudo cat /etc/network/interfaces”
# Specific to the Server at 70.86.44.10 which belongs to Indus Net
alias psrv=’ping 70.86.44.10 -c 5′
alias srv=’ssh root@70.86.44.10‘
alias srv2=’ssh root@70.85.88.212‘
# Quick Open Files for editting or viewing.
alias als=’$bjEditor ~/.bash_aliases’
alias lals=’less ~/.bash_aliases’
alias du1=’du –max-depth=1′
alias du2=’du –max-deth=2′
# Auto Parameter
alias tarc=’tar -cvvf’
alias bjgrep=”grep -r –include=’*.(php|html)’ ”
alias cpr=’cp -R’
# Taken from http://ubuntuforums.org/showthread.php?t=679762
alias hs=’history’
alias clr=’clear’
# System info
alias cpuu=”ps -e -o pcpu,cpu,nice,state,cputime,args –sort pcpu | sed ‘/^ 0.0 /d'”
alias memu=’ps -e -o rss=,args= | sort -b -k1,1n | pr -TW$COLUMNS’
alias pg=’ps aux | grep’ #requires an argument
# chmod and permissions commands
alias mx=’chmod a+x’
alias 000=’chmod 000′
alias 644=’chmod 644′
alias 755=’chmod 755′
alias perm=’stat –printf “%a %n \n “‘ # requires a file name e.g. perm file
# Exim Aliases
alias bjexiclean=’echo “Removing all mails with no sender set”; exiqgrep -f “^$” -i | xargs exim -Mrm’
alias bjexifrozen=’exiqgrep -z -i | xargs exim -Mrm’
alias bjexiqueue=’exim -bp > $dumpdir/exim/queue_all; less $dumpdir/exim/queue_all’
I had to use a file called ~/.bashrc instead of ~/.bash_profile on my LMDE system with KDE and Linux 3.0.0-1-amd64. Other than that note thanks for writing this. I needed a way to keep Bash from saving multiple duplicate lines in my history since I often reuse that last command and you showed me how to do it. I owe you a beverage.
Thanks for that great list. Is there an easy way to set those settings for all users in one file? Or do I really have to edit each users .bash_rc file?