Difference between revisions of "Linux - A better .bashrc for root"

From Da Nerd Mage Wiki
Jump to navigation Jump to search
(Created page with "<span ><code class="mwt-code" ></code></span> # ~/.bashrc: executed by bash(1) for non-login shells. <span ><code class="mwt-code" ></code></span> <br>PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' <span ><code class="mwt-code" ></code></span> <br># If this is an xterm set the title to user@host:dir<br>case "$TERM" in<br>xterm*{{!}}rxvt*)<br>    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h:...")
 
Line 1: Line 1:
<span ><code class="mwt-code" ></code></span>
In your root users home directory (generally <code>/root</code>), there should be a file named <code>.bashrc</code>.  If not, you can create it from scratch.


# ~/.bashrc: executed by bash(1) for non-login shells.
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.


<span ><code class="mwt-code" ></code></span>
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.


<br>PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
<syntaxhighlight lang="bash" line>
 
# ~/.bashrc: executed by bash(1) for non-login shells.
<span ><code class="mwt-code" ></code></span>
 
<br># If this is an xterm set the title to user@host:dir<br>case "$TERM" in<br>xterm*{{!}}rxvt*)<br>&nbsp; &nbsp; PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"<br>&nbsp; &nbsp; ;;<br>*)<br>&nbsp; &nbsp; ;;<br>esac
 
<span ><code class="mwt-code" ></code></span>
 
<br># set a fancy prompt (non-color, unless we know we "want" color)<br>case "$TERM" in<br>&nbsp; &nbsp; xterm-color{{!}}*-256color) color_prompt=yes;;<br>esac
 
<span ><code class="mwt-code" ></code></span>
 
<br># umask 022
 
<span ><code class="mwt-code" ></code></span>
 
<br># You may uncomment the following lines if you want `ls' to be colorized:<br>&nbsp;export LS_OPTIONS='--color=auto'<br>&nbsp;eval "$(dircolors)"<br>&nbsp;alias ls='ls $LS_OPTIONS'
 
<span ><code class="mwt-code" ></code></span>
 
<br># some handy ls aliases<br>alias ll='ls -lAh'<br>&nbsp;alias l='ls -lA'<br>alias la='ls -A'<br>alias lf='ls -F'
 
<span ><code class="mwt-code" ></code></span>
 
<br># Some more alias to avoid making mistakes:<br># alias rm='rm -i'<br># alias cp='cp -i'<br># alias mv='mv -i'
 
<span ><code class="mwt-code" ></code></span>


<br># don't put duplicate lines or lines starting with space in the history.<br># See bash(1) for more options<br>HISTCONTROL=ignoreboth
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '


<span ><code class="mwt-code" ></code></span>
# 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


<br># append to the history file, don't overwrite it<br>shopt -s histappend
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac


<span ><code class="mwt-code" ></code></span>
# umask 022


<br># for setting history length see HISTSIZE and HISTFILESIZE in bash(1)<br>HISTSIZE=1000<br>HISTFILESIZE=2000
# 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'


<span ><code class="mwt-code" ></code></span>
# some handy ls aliases
alias ll='ls -lAh'
alias l='ls -lA'
alias la='ls -A'
alias lf='ls -F'


<br># check the window size after each command and, if necessary,<br># update the values of LINES and COLUMNS.<br>shopt -s checkwinsize
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'


<span ><code class="mwt-code" ></code></span>
# 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


<code class="mwt-code" ></code>
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
</syntaxhighlight>

Revision as of 14:38, 16 May 2022

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