I think my observation linux to navigate to the previous directory (or back) command is cd- but it is not working code cd-
Asked
Active
Viewed 1.3k times
2
ChanganAuto
- 1
- 8
- 15
- 23
1 Answers
8
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.
steeldriver
- 142,475