August 21, 2008 Archives

2008-08-21 19:53:24

Useful bash functions I

Put the following in your ~/.bashrc

up() {
        if [ $# == 0 ]
        then 
                cd ..
                return  
        fi
        if [ "${1//[^0-9]/}" != "$1" ]
        then
                echo "Not a number"
                return
        fi
        STRING=""
        for (( i=0; i<$1 ; i++ ))
        do 
                STRING="$STRING../"
        done
        cd $STRING
}

up is equivalent to cd .. and up N jumps up N directories in the directory tree.

Posted by haui | Permanent Link | Categories: linux