Change directory helper function

This function might be the most useful one in my own scripts, and I had introduced it for several times.

Let’s say you are working in a big project such as Android Framework, or your are a command-line heavy user. The change-directory-command, cd, would be typed thounsands times per day. THAT IS SO ANNOYING!.

Try adding this function to ~/.bashrc

1
2
3
4
5
6
7
8
..() {
    num=$1
    test $1 || num=1
    seq=`seq $num`
    next=`printf '../%.0s' {$seq}`
    cd $next
    ls
}

suppose you are in /home/foo/L1/L2/L3/L4

1
2
3
4
$ .. # will go to L3
$ .. 2 # will go to L2
$ .. 3 # will go to L1
$ .. 100 # will go to /