Is there a command for going back a number of steps in a directory, without using cd?

Put this in your ~/.bashrc:

cdup() {
  levels=${1-1}
  while ((levels--)); do
    cd ..
  done
}

(The name cdup comes from the corresponding FTP command, just FYI.)


I was taught to use 'pushd' and 'popd' for such circumstances.

For example, type 'pushd .' and then 'cd /home'. Now type 'popd' and you will be back to where you started.

'pushd'/'popd' is a stack, you can push as many directories on there as you like, but it is last on, first off when you popd.


Sure, why not:

up() {
    [ $# = 0 ] && cd .. && return
    [ $1 = 0 ] && return
    cd .. && up $(($1 - 1))
}