Last Updated: February 25, 2016
·
422
· spencerwi

up -- useful bash alias

Works in bash and zsh; saves me from typing "cd ../../../../../.." etc when navigating deeply-nested directory structures (like for Java projects).

Usage: up [N]

For example: "up 11" is equivalent to "cd .." 11 times. Just "up" is equivalent to "cd .."

up () {
        if (( $# != 1 ))
        then
                cd ..
        else
                upstr="." 
                for i in {1..$1}
                do
                        upstr="$upstr/.." 
                done
                cd $upstr
        fi
}