Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Consider:

$ pwd
/home/user
$ ls -l
total 3604
lrwxrwxrwx 1 user user  19 Nov 27 12:11 pages -> /var/www/pages/

$ cd pages
$ pwd
/home/user/pages
$ readlink -f .
/var/www/pages

$ cd ..
$ readlink -f .
/home/user
$ 

When I'm in /var/www/pages I would like to go up to /var/www however running cd .. brings me to /home/user. Obviously this is due to having gotten to /var/www/pages via a symlink. How can I cd up one directory when I'm in a symlink?

share|improve this question

1 Answer 1

up vote 9 down vote accepted

cd -P ..
You should read more preciscly manual ;-)

share|improve this answer
    
Thanks! Actually, I tried to read the fine manual however No manual entry for cd, and info cd gives irrelevant information. This is on two Ubuntu systems. –  dotancohen Nov 27 '13 at 12:55
    
cd is a build in shell command so so man is not exciting, but man cd give good result in google ;) –  Kiwy Nov 27 '13 at 12:56
1  
@dotancohen cp --help generally gives short info compared to the main page (or in this case, all the info since it doesn't have a man page) –  Izkata Nov 27 '13 at 14:59
2  
@dotancohen Because cd is built in to the shell, you can find the documentation for it inside the shell manual (man bash). Scroll down to the "SHELL BUILTIN COMMANDS" section. Also a general search for cd in that man page is illuminating; it will teach you about $OLDPWD, $CDPATH, and some other fun stuff. –  dg99 Nov 27 '13 at 16:32
    
alias back=cd "$OLDPWD" –  Rob Nov 27 '13 at 17:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.