Friday, May 3, 2024
27
rated 0 times [  27] [ 0]  / answers: 1 / hits: 17906  / 2 Years ago, mon, september 26, 2022, 8:16:20

I typed cd - in terminal by mistake today, and I got an error saying:



bash: cd: OLDPWD not set


And unfortunately, man cd doesn't exist.



No manual entry for cd


What does it actually do?


More From » command-line

 Answers
5

cd - switches between the old and new present working directories.


avinash@avinash:~$ cd -
bash: cd: OLDPWD not set
avinash@avinash:~$ cd ~/Desktop
avinash@avinash:~/Desktop$ pwd
/home/avinash/Desktop
avinash@avinash:~/Desktop$ cd -
/home/avinash
avinash@avinash:~$

See also,


avinash@avinash:~$ echo $OLDPWD

avinash@avinash:~$ cd ~/Desktop
avinash@avinash:~/Desktop$ echo $OLDPWD
/home/avinash
avinash@avinash:~/Desktop$ cd d
avinash@avinash:~/Desktop/d$ echo $OLDPWD
/home/avinash/Desktop
avinash@avinash:~/Desktop/d$

The $OLDPWD variable stores the path of the previous present working directory.


[#27350] Wednesday, September 28, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
guialk

Total Points: 300
Total Questions: 144
Total Answers: 121

Location: Saint Vincent and the Grenadines
Member since Sat, Sep 11, 2021
3 Years ago
;