Nov/090
Speed up apt-get with axel and apt-fast.
Web Upd8 has a nice article on a bash script by Matt Parnell that uses axel to increase the speed of apt-get updates. Basically, install axel then use this script instead of apt-get:
#!/bin/sh #apt-fast by Matt Parnell http://www.mattparnell.com , this thing is FOSS #please feel free to suggest improvements to admin@mattparnell.com # Use this just like apt-get for faster package downloading. Make sure to have axel installed #If the first user entered variable string contains apt-get, and the second string entered is either install or dist-upgrade if echo "$1" | grep -q "[upgrade]" || echo "$2" | grep -q "[install]" || echo "$2" | grep -q "[dist-upgrade]"; then echo "Working..."; #Go into the directory apt-get normally puts downloaded packages cd /var/cache/apt/archives/; #Have apt-get print the information, including the URI's to the packages apt-get -y --print-uris $1 $2 $3 $4 > debs.list; #Strip out the URI's, and download the packages with Axel for speediness egrep -o -e "(ht|f)tp://[^\']+" debs.list | xargs -l1 axel -a; #Perform the user's reqested action via apt-get apt-get -y $1 $2 $3 $4; echo "Done! Make sure and check to see that the packages all were installed properly. If a package is erred, run sudo apt-get autoclean and try installing it again without the use of this script."; elif echo "$1" | grep -q "[*]"; then apt-get $1; else echo "Sorry, but you appear to be entering invalid options. You must use apt-get and one of apt-get's options in order to use this script."; fi

May/090
BASH case insensitive path checking. (effificently)
I needed to check some paths for files. I have a script that calls a copy function on some files that were previously mounted on a case insensitve system. I couldn’t find anything, so instead of using `find -i` which would be a resource hog i wrote this: –
#!/bin/bash
old_IFS=$IFS
if ! [ -a $1 ]; then
trypath=""
path=""
IFS=$'/'
for i in $1; do
trypath=$path$i"/"
if [[ -a $trypath ]]; then
path=$trypath
else
ipath=`ls "$path" | grep -i $i`
path=$path$ipath"/"
fi
done
echo "$path"
else
echo "exists"
fi
IFS=$old_IFS
Jul/080
*nix bash while read line do – to proccess all files in a direcotry tree. because i keep forgetting….
I keep forgetting the syntx for while read.
essentially, you pipe a bunch of lines into it, and then it’ll process each line e.g.:
$find ~/video -iname ‘*avi’ -or -iname ‘*mpeg’ | while read movie ; do
mencoder [encoding options...] “$movie” -o ~/converted/`basename
“$movie”` ; done
Yay.
Jun/081
Customising your bash prompt in OsX – path in the title bar & pretty colors!
I made myself a nice prompt for bash in OsX, I have the basename of the path in the terminal, but he full path in the title bar. Yay!
put this in your .bashrc (see prevoius post on creating this file)
export PS1="\[\e]2;\u@\H \w\a\e[42;1m\]\u:\W>\[\e[0m\] "
To customise:
\a an ASCII bell character (07)
\d the date in “Weekday Month Date” format (e.g., “Tue May 26″)
\e an ASCII escape character (033)
\h the hostname up to the first `.’
\H the hostname
\n newline
\r carriage return
\s the name of the shell, the basename of $0 (the portion following the final slash)
\t the current time in 24_hour HH:MM:SS format
\T the current time in 12_hour HH:MM:SS format
@ the current time in 12_hour am/pm format
\u the username of the current user
\v the version of bash (e.g., 2.00)
\V the release of bash, version + patchlevel (e.g., 2.00.0)
\w the current working directory
\W the basename of the current working directory
\! the history number of this command
# the command number of this command
\$ if the effective UID is 0, a #, otherwise a $
\nnn the character corresponding to the octal number “nnn”
\\ a backslash
\[ begin a sequence of non_printing characters
\] end a sequence of non_printing characters
;
and here is a list of color codes (it’s displayed in such a way as so you can just export it, and see the colours)
PS1='[\u@TEST \w]\n \#\$ \n\ \[\ \e[1mBold Text\e[m\n\ \e[4mUnderline Text\e[m\n\ \e[5mBlink Text\e[m\n\ \e[7mInverse Text\e[m\]\n\ Should be normal text Foreground colors: \[\ \e[0;30m30: Black\n\ \e[0;31m31: Red\n\ \e[0;32m32: Green\n\ \e[0;33m33: Yellow\Orange\n\ \e[0;34m34: Blue\n\ \e[0;35m35: Magenta\n\ \e[0;36m36: Cyan\n\ \e[0;37m37: Light Gray\Black\n\ \e[0;39m39: Default\n\ Bright foreground colors: \e[1;30m30: Dark Gray\n\ \e[1;31m31: Red\n\ \e[1;32m32: Green\n\ \e[1;33m33: Yellow\n\ \e[1;34m34: Blue\n\ \e[1;35m35: Magenta\n\ \e[1;36m36: Cyan\n\ \e[1;37m37: White\n\ \e[0;39m39: Default\n\ \e[m\]Background colors: \[\e[1;37m\e[40m40: Black\e[0;49m\n\ \e[41m41: Red\e[0;49m\n\ \e[42m42: Green\e[0;49m\n\ \e[43m43: Yellow\Orange\e[0;49m\n\ \e[44m44: Blue\e[0;49m\n\ \e[45m45: Magenta\e[0;49m\n\ \e[46m46: Cyan\e[0;49m\n\ \e[47m47: Light Gray\Black\e[0;49m\n\ \e[49m49: Default\e[m\]\n'
more reading: http://networking.ringofsaturn.com/Unix/Bash-prompts.php
May/080
Os X console. howto setup your .bashrc
I’m new to OsX, but not to *nix, so one of the first things that i wanted to do was to set up my console…
this is my ~/.bash_profile
. ~/.bashrc ENV=$HOME/.bashrc export ENV
and my ~/.bashrc:
PATH=$PATH:$HOME/bin:/usr/local/bin:/usr/libexec alias lc=ls alias l="ls -l" alias ll="ls -l" alias la="ls -a" SHELL=/bin/bash export CLICOLOR=1 export LSCOLORS=ExFxCxDxBxegedabagacad