LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Get back to original directory (https://www.linuxquestions.org/questions/linux-newbie-8/get-back-to-original-directory-775623/)

faizlo 12-14-2009 02:57 PM

Get back to original directory
 
Hi,

Sometimes I cd to a linked directory, and when I issue cd .., it takes me one level back, but not to the parent directory in which the link was there, but the true parent directory of the linked directory (I hope I could spell it clearly!).

How to get back to the parent directory (the one which has the link) from within the linked directory?

PS:
even cd - does not help

~hatim

worm5252 12-14-2009 03:02 PM

The easiest way is to always know where you are at. Another way is instead of doing 'ls' for find the directories, do 'ls -l' so you can find the links and see where they go. Then you can do an 'ls' on the link location. i.e. 'ls <linklocation>'

markush 12-14-2009 03:03 PM

Hello faizlo,

in bash the variable OLDPWD is the "old working directory". So
Code:

cd $OLDPWD
will bring you back to there.

Markus

pixellany 12-14-2009 03:06 PM

On my system, "cd -" and "cd .." both take me back to where I was. If I drill down, cd ../.. also takes me to the original starting point. So......maybe this means there is a config file somewhere???

markush 12-14-2009 03:10 PM

Hello together,

many Linuxdistributions come with the aliases
Code:

alias ..='cd ..' and
alias ...='cd ../..'

Markus

pixellany 12-14-2009 03:12 PM

Quote:

Originally Posted by markush (Post 3791367)
Hello together,

many Linuxdistributions come with the aliases
Code:

alias ..='cd ..' and
alias ...='cd ../..'

.

Markus

If "cd .." does not work as desired, then how would this alias help?

faizlo 12-14-2009 03:13 PM

Thank you all for the quick response (which make feel guilty of not posting before :) )
Markush, your trick worked. I will create an alias "back, or orig" and insert it in my .bashrc file.

Thank you all again,

~faizlo

faizlo 12-14-2009 03:16 PM

cd $OLDPWD worked with bash, but not with tcsh :(
It say, OLDPWD: undefined variable.
Any hints!?

~faizlo

markush 12-14-2009 03:23 PM

Hi,

in tcsh "cd -" should work (refering to the manpage). I'd recommend to read the manpage and search for "working"
Code:

man tcsh
and in the manpage execute
Code:

/working
Markus

faizlo 12-14-2009 04:50 PM

On tcsh shells, the command is: cd $owd (small letters)

~faizlo


All times are GMT -5. The time now is 03:43 AM.