Linux - A better .bashrc for root

From Da Nerd Mage Wiki
Revision as of 14:38, 16 May 2022 by Tinker (talk | contribs)
Jump to navigation Jump to search

In your root users home directory (generally /root), there should be a file named .bashrc. If not, you can create it from scratch.

The following is what I tend to put in that file. It has a few extras that the defaults generally don't. These are intended to make life easier.

One thing in particular is the RED prompt colouring. Just to remind you when you're logged in as root & capable of completely destroying your system inadvertently.

# ~/.bashrc: executed by bash(1) for non-login shells.

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# umask 022

# You may uncomment the following lines if you want `ls' to be colorized:
 export LS_OPTIONS='--color=auto'
 eval "$(dircolors)"
 alias ls='ls $LS_OPTIONS'

# some handy ls aliases
alias ll='ls -lAh'
 alias l='ls -lA'
alias la='ls -A'
alias lf='ls -F'

# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize