Configuring Linux
This page is a dump of my linux configurations.
Ubuntu sudo and su -
Having spent many years using linux I've got used to running a root terminal and since the I've moved onto ubuntu I've been having a bit of gripe with the sudo.
I'm so used to running some commands without sudo and I've especially got used to the !sub-string-cmd to replay an prev command, with sudo this isn't any good.
I'm fully aware of the benefits that sudo brings, but I'm too stuck in my ways to want to change now.
┌─(andrew@ilread Mon, 08 Jun 09)─—————————————————————————————————————————————————————─(/home/andrew)────┐
└─(16:20 $)─>sudo -s
┌─(root@ilread Mon, 08 Jun 09)─—————————————————————————————————————————————————————─(/home/andrew)────┐
└─(16:20 $)─>
sudo has a -s switch that will drop you into a root account so you can forget about the need to prefix any su - commands.
Setting Up .bashrc
I use the command line a whole bunch, on my gentoo boxes I was used to using fluxbox and with it the urxvt or zsh shells. On my ubuntu I'm still using gnome (atm) and with it bash in gnome-terminal.
Here's how I have configured my .bashrc to make it feel more "normal" or more like what I'm used to.
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
# ... or force ignoredups and ignorespace
export 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)
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
function pre_prompt {
newPWD="${PWD}"
user="whoami"
host=$(echo -n $HOSTNAME | sed -e "s/[\.].*//")
datenow=$(date "+%a, %d %b %y")
let promptsize=$(echo -n "--($user@$host ddd, DD mmm YY)---(${PWD})---" \
| wc -c | tr -d " ")
let fillsize=${COLUMNS}-${promptsize}
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="${fill}—"
let fillsize=${fillsize}-1
done
if [ "$fillsize" -lt "0" ]
then
let cutt=3-${fillsize}
newPWD="...$(echo -n $PWD | sed -e "s/\(^.\{$cutt\}\)\(.*\)/\2/")"
fi
}
PROMPT_COMMAND=pre_prompt
export black="\[\033[0;38;5;0m\]"
export red="\[\033[0;38;5;1m\]"
export green="\[\033[0;38;5;2m\]"
export yellow="\[\033[0;38;5;3m\]"
export blue="\[\033[0;38;5;4m\]"
export magenta="\[\033[0;38;5;55m\]"
export cyan="\[\033[0;38;5;6m\]"
export white="\[\033[0;38;5;7m\]"
export coldblue="\[\033[0;38;5;33m\]"
export smoothblue="\[\033[0;38;5;111m\]"
export iceblue="\[\033[0;38;5;45m\]"
export turqoise="\[\033[0;38;5;50m\]"
export smoothgreen="\[\033[0;38;5;42m\]"
PS1="$green┌─($coldblue\u@\h \$(date \"+%a, %d %b %y\")$green)─\${fill}─($coldblue\$newPWD\
$green)────┐\n$green└─($coldblue\$(date \"+%H:%M\") \$$green)─>$white "
unset color_prompt force_color_prompt
# 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
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
#if [ -f ~/.bash_aliases ]; then
# . ~/.bash_aliases
#fi
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
eval "`dircolors -b`"
alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
#alias egrep='egrep --color=auto'
fi
# some more ls aliases
alias ll='ls -lh'
alias la='ls -A'
alias l='ls -CF'
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
#netinfo - shows network information for your system
netinfo ()
{
echo "--------------- Network Information ---------------"
/sbin/ifconfig | awk /'inet addr/ {print $2}'
/sbin/ifconfig | awk /'Bcast/ {print $3}'
/sbin/ifconfig | awk /'inet addr/ {print $4}'
/sbin/ifconfig | awk /'HWaddr/ {print $4,$5}'
myip=`lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g' `
echo "${myip}"
echo "---------------------------------------------------"
}
#dirsize - finds directory sizes and lists them for the current directory
dirsize ()
{
du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \
egrep '^ *[0-9.]*[MG]' | sort -n > /tmp/list
egrep '^ *[0-9.]*M' /tmp/list
egrep '^ *[0-9.]*G' /tmp/list
rm -rf /tmp/list
}
#copy and go to dir
cpg (){
if [ -d "$2" ];then
cp $1 $2 && cd $2
else
cp $1 $2
fi
}
#move and go to dir
mvg (){
if [ -d "$2" ];then
mv $1 $2 && cd $2
else
mv $1 $2
fi
}
# Define a word - USAGE: define dog
define ()
{
lynx -dump "http://www.google.com/search?hl=en&q=define%3A+${1}&btnG=Google+Search" | grep -m 5 -w "*" | sed 's/;/ -/g' | cut -d- -f5 > /tmp/templookup.txt
if [[ -s /tmp/templookup.txt ]] ;then
until ! read response
do
echo "${response}"
done < /tmp/templookup.txt
else
echo "Sorry $USER, I can't find the term \"${1} \""
fi
rm -f /tmp/templookup.txt
}
# Directory navigation aliases
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
# ps details
alias pscpu='ps -eo pcpu,nice,stat,time,pid,cmd --sort=-pcpu,-time \
| sed "/^ 0.0 /d"'
alias psmem='ps -eo rss,vsz,pid,cmd --sort=-rss,-vsz \
| awk "{ if (\$1 > 10000) print }"'
# facts of the day
alias today='grep -h -d skip `date +%m/%d` /usr/share/calendar/*'
# Commands frequency counts
alias cmdfreq='cut -d " " -f 1 < $HISTFILE | sort | uniq -c | sort -nr | head -n 10'
# grep process by name and list the results nicely
pg () {
if pgrep -f $@ > /dev/null;
then
pgrep -f $@ | xargs ps -o user,pid,stat,rss,vsz,pcpu,args \
--sort -pcpu,-rss ;
else
exit 1;
fi
}
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
clear
echo -ne $turqoise "Hello, $USER. today is, "; date
echo -e "${WHITE}"; cal -3;
echo -e "${WHITE}"; uname -a ;
echo ""
I can't take any credit for any of the content I took a bunch off "Show us your .bashrc" post on the ubuntuforums web site.
Last Updated : 08/06/2009 @ 17:32