Adriano Chiaretta

Recipe for a better bash

If you happen to have fun from time to time with *nix shells, and bash in particular, you’ve probably noticed that the command history will soon fill itself up with same-sort-of-commands such the usual ‘ls -la’, ‘uptime’, ‘df -ah’, etc.

Side effect of this is when you want to go back and quickly get to a previously issued commands, you’ll end up pressing up arrow a number of time wading through never ending same commands.

Solution to make your life a bit easier is better_bashrc — just save the zip file somewhere, unzip and replace your current .bashrc (user’s home), log out then back in and you’re good to go.

Or, copy paste what below in your current .bashrc file.

# ———————- copy what below —————

# .bashrc

# User specific aliases and functions

alias rm=’rm -i’
alias cp=’cp -i’
alias mv=’mv -i’

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# This will append any new history to the existing file rather than rewriting it
shopt -s histappend
PROMPT_COMMAND=’history -a’

# This will ignore simple mistakes such as typing otp instead of opt, or ect instead of etc.
shopt -s cdspell

# Remove duplicates in your history
export HISTCONTROL=”ignoredups”
export HISTIGNORE=”&:ls:[bf]g:exit”

# This will ensure that multiple line commands stay together in your history.
shopt -s cmdhist

# ———————- copy what above —————

You can find more tips here.

Leave a Comment