.bash login

From Linux Bash Shell Scripting Tutorial Wiki
Jump to navigation Jump to search

The .bash_login file is located in users $HOME directory.

What is .bash_login file?

When bash is invoked as an interactive login shell, it will run commands from .bash_login file.


This file is located in the user's home directory. If not exists, one can create it. For example, use the ls command or cat command as follows:

ls -l ~/.bash_login
cat ~/.bash_login


Interactive login bash first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for the following file in that order and reads and executes commands from the first one that exists and is readable by the user session:

  1. ~/.bash_profile
  2. ~/.bash_login
  3. ~/.profile


Here is my sample ~/.bash_login file:

export PS1="\[\e[31m\][\[\e[m\]\[\e[38;5;172m\]\u\[\e[m\]@\[\e[38;5;153m\]\h\[\e[m\] \[\e[38;5;214m\]\W\[\e[m\]\[\e[31m\]]\[\e[m\]\\$ "

         .'     '.
        /  _   _  \
        | (o)_(o) |
         \(     ) /
         //'._.'\ \
        //   .   \ \
       ||   .     \ \
       |\   :     / |
       \ `) '   (`  /_
     _)``".____,.'"` (_
     )     )'--'(     (
      '---`      `---`

# The next line updates PATH for the Google Cloud SDK.
if [ -f '/home/vivek/google-cloud-sdk/path.bash.inc' ]; then . '/home/vivek/google-cloud-sdk/path.bash.inc'; fi

# The next line enables shell command completion for gcloud.
if [ -f '/home/vivek/google-cloud-sdk/completion.bash.inc' ]; then . '/home/vivek/google-cloud-sdk/completion.bash.inc'; fi

export HISTCONTROL=ignoreboth:erasedups
shopt -s histappend
export PROMPT_COMMAND="history -a; history -n"
export HISTIGNORE="ls:ll:cd:pwd:bg:fg:history"
export HISTSIZE=100000
export HISTFILESIZE=10000000
shopt -s histappend histreedit histverify
shopt -s no_empty_cmd_completion
export HISTTIMEFORMAT="%d/%m/%y %T "
alias update='sudo -- sh -c "apt update && apt -y upgrade && apt -y --purge autoremove && sudo apt -y clean"'
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
alias l.='ls -d .* --color=auto'
alias xzegrep='xzegrep --color=auto'
alias xzfgrep='xzfgrep --color=auto'
alias xzgrep='xzgrep --color=auto'
alias zegrep='zegrep --color=auto'
alias zfgrep='zfgrep --color=auto'
alias zgrep='zgrep --color=auto'

export PATH=$PATH:/home/vivek/.2fa/
	local services
	services=$(find "/home/vivek/.2fa/" -type d -printf "%f " | sed 's/.2fa\///')
	complete -W "$services" decrypt.key.sh
	complete -W "$services" ~/.2fa/decrypt.key.sh

complete -F _decrypt_key_sh decrypt.key.sh
complete -C '/usr/local/bin/aws_completer' aws
export EDITOR=vim
export VISUAL=vim

Getting help

Use the man command:

man bash