Hacking by Walkingice: change directory helper function

2012/08/15

change directory helper function

I wrote an article about it long time ago, now I write again to avoid lost my function.

If you are working in a big project such as Android, you will find that changing directory in a deep tree is painful.

Try adding this function to ~/.bashrc
..() {
    num=$1
    test $1 || num=1
    seq=`seq $num`
    next=`printf '../%.0s' {$seq}`
    cd $next
    ls
}

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

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

3 comments: