cdup Fun!

November 6, 2003

Richard (richlowe) and a few other people from #fu were talking about being able to do things like cdup 5 to jump up 5 directories. I thought it would be nicer if my existing .. alias took an optional argument to do the same thing. Here's the result (for bash):

function cdup() {
  if [ "x$1" = "x" ]; then max=1; else max=$1; fi
  for ((i=0; i<$max; i++)); do cd ..; done 
}

alias ..="cdup";

So .. works the same as it did before, but now you can do stuff like this:

pabs@vault:/usr/local/share/raggle/themes> ..
pabs@vault:/usr/local/share/raggle> .. 2
pabs@vault:/usr/local> 

Richard's version does the same thing for zsh.