O comando
cd -
realizará a troca que você precisa na maioria dos shells convencionais, a variante mais antiga é
cd "$OLDPWD"
que usará a variável de ambiente que contém o diretório de trabalho anterior.
A página man do POSIX para cd
menciona:
DESCRIPTION
If, during the execution of the above steps, the PWD environment variable is changed, the OLDPWD environment variable shall also be changed to the value of the old working directory (that is the current working directory immediately prior to the call to cd).
OPERANDS
- When a hyphen is used as the operand, this shall be equivalent to the command:
cd "$OLDPWD" && pwd
which changes to the previous working directory and then writes its name.