What is linux command to navigate to the previous directory (or back)? [duplicate]
I think my observation linux to navigate to the previous directory (or back) command is cd- but it is not working code cd-
1 Answer
You need a space before the -, so that it is passed as an argument to the cd command:
From man bash:
An argument of - is converted to $OLDPWD before the directory change is attempted.
This is different from cd .. which changes to the parent directory, rather than to $OLDPWD. You may of course define aliases for either or both if you wish, ex. alias cd-='cd -' and alias cd..='cd ..' but they are not defined as such by default.
See also:
You might also want to take a look at the bash shell's pushd and popd commands, which allow more complete access to the directory stack.