the uses of .bash_profile and .bashrc

Difference of .bash_profile and .bashrc

.bash_profile is the one being executed upon login on your machine. mostly you add diagnostic commands (uptime, disk space utilization, iostats, etc) that you want to be shown upon login.

.bashrc file determines the behavior of interactive shells. every aliases and functions you put on this file will be available even when you open a new terminal window.

 .bash_profile’s usefulness

On my bash_profile. I always show diagnostic information that i want to be shown upon login ONLY. below is my basic .bash_profile

echo "----- Server Load -----"
mkdir diagnostics -p
uptime > diagnostics/load_avg-`date +%F_%H:%M`.txt
cat diagnostics/load_avg-`date +%F_%H:%M`.txt

echo "----- Disk Space -----"
df -h > diagnostics/disk_space-`date +%F_%H:%M`.txt
cat diagnostics/disk_space-`date +%F_%H:%M`.txt

I always keep a diagnostic folder on my home folder for easier retrieval.


on your .bashrc you can define aliases, simple day to day functions and spelling corrections.

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias ll="ls -l --group-directories-first"
alias ls='ls -hF --color'  # add colors for filetype recognition
alias la='ls -Al'          # show hidden files
alias lx='ls -lXB'         # sort by extension
alias lk='ls -lSr'         # sort by size, biggest last
alias lc='ls -ltcr'        # sort by and show change time, most recent last
alias lu='ls -ltur'        # sort by and show access time, most recent last
alias lt='ls -ltr'         # sort by date, most recent last
alias lm='ls -al |more'    # pipe through 'more'
alias lr='ls -lR'          # recursive ls
alias tree='tree -Csu'     # nice alternative to 'recursive ls'

# spelling correction
alias shh='ssh'

function c(){
	grep $1 /etc/hosts

function extract()      # Handy Extract Program.
     if [ -f $1 ] ; then
         case $1 in
             *.tar.bz2)   tar xvjf $1     ;;
             *.tar.gz)    tar xvzf $1     ;;
             *.bz2)       bunzip2 $1      ;;
             *.rar)       unrar x $1      ;;
             *.gz)        gunzip $1       ;;
             *.tar)       tar xvf $1      ;;
             *.tbz2)      tar xvjf $1     ;;
             *.tgz)       tar xvzf $1     ;;
             *.zip)       unzip $1        ;;
             *.Z)         uncompress $1   ;;
             *.7z)        7z x $1         ;;
             *)           echo "'$1' cannot be extracted via >extract

the “c” function on my bashrc is my most used command. i handle a lot of servers and i need a quick way to check ip addresses based on my host file.

“ll” command is also my favorite command which is an alias of ‘ls -l’. this alias is part of the default .bashrc of ubuntu but not on linux mint. has an enormous compilation of bashrc commands you can tailor yours from them,

Leave a Reply

Your email address will not be published. Required fields are marked *