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,075 times
2
ChanganAuto
- 1,940
- 8
- 14
- 21
-
Do not add the dash. That is a completely invalid command, just by adding the dash makes the command invalid. To go back, simply type cd and press enter (again. no dash) – Logan Apr 28 '21 at 15:23
-
I don't really know if that was an accident or not when you put the dash, but it was done twice, so I can't tell. – Logan Apr 28 '21 at 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
- 131,985
- 21
- 239
- 326