I have directories set up a bit like this

~/code/build -> /path/to/somewhere/else

That last one's a symlink.

If I do this

cd ~/code/build
ls ..

then I get the listing for /path/to/somewhere, but from other remarks and my own experience, I'd expected to see the listing for ~/code -- I'd swear that this used to work the other way round.

I'm using zsh and bash on Ubuntu. Is there a setting for this or is it deeply ingrained into POSIX or something?

  • ls -- "$(dirname -- "$PWD")"
    – cuonglm
    Jan 25, 2015 at 17:11

2 Answers 2


Not the issue of ls. It's how symlinks work. The .. gets you into the parent of the current directory, the directory doesn't know you got to it through a symlink. The shell has to intervene to prevent this behaviour. For the shell builtin cd, there is special handling that doesn't just call chdir but memorizes the full directory path and tries to figure out what you want. ls, however, is not a builtin. The shell has to change .. to a different path before passing it to ls if you want to get what you expect. zsh option CHASE_DOTS helps you with that.

Generally speaking, symlinks to directories are a dirty business. For critical and semi-permanent applications, rather use mount --bind.

  • I don't get it. I've tried setopt CHASE_DOTS and unsetopt CHASE_DOTS in ~/.zshrc (with restart) also tried unsetopt and combinations. Nothing seemed to make a difference. Also, doesn't the shell interpret ".." before passing it to both cd and ls?
    – spraff
    Jan 26, 2015 at 13:48
  • Sorry, I checked it now and it appears that all these options only work for cd. zsh is not substituting the filenames given to other commands (kind of obvious now, it can't actually know what is a filename and what isn't). I don't think this will ever work as you wanted. The closest thing I can imagine to actually get the parent directory you came from is to replace .. with $(cd .. && pwd). This launches a subshell that cd's there and reads the link. But generally speaking, don't use symlinks to directories. Use bind mounting.
    – orion
    Jan 26, 2015 at 14:17
  • mount --bind works, but I anticipate a problem if I add the line to fstab, my home directory is encrypted so an entry which looks like /path/to/somewhere/else /home/me/code/build none rw,bind, 0 0 will fail won't it?
    – spraff
    Jan 26, 2015 at 16:44
  • It depends on the order, it should work, if the home is already mounted.
    – orion
    Jan 26, 2015 at 17:08

Since you tagged your question with zsh I assume we are talking about this shell.

Most probably you have set (either directly or indirectly with some external script like oh-my-zsh) the variables CHASE_LINKS and/or CHASE_DOTS. To confirm that run setopt | grep -i chase and see if they are listed. If they are, just unset them:

unsetopt CHASE_DOTS
unsetopt CHASE_LINKS

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .