This entry is part 3 of 19 in the Bash-whacking series

Ever thought typing cd.. 5 times was silly? Try this up() function!

Add this to .bash_profile or .bashrc

up () {
    if [ -z $1 ]; then
        cd ..
    elif [ $1 -gt 0 ]; then
        let count=0
        while [ $count -lt $1 ]; do
            cd ..
            let count=count+1
        done
    else
        echo "Argument must be a positive integer."
    fi
    pwd
}

The script in action:

kelvin:~/java/search/apache-solr-1.4.0/src/java/org/apache/solr/search$ up 5
kelvin:~/java/search/apache-solr-1.4.0/src$