View Full Version : "ls" and "cd" treat ".." differently inside symlinked directories

19th June 2008, 04:49 PM
First, let me say that I'm really enjoying using Fedora 9. Thanks for a great distribution!

Now the problem: I've been using Linux daily for well over a decade, and this is new to me.

My development tree fails miserably now due to what seems like very strange behavior with symlinks. I notice this on both i386 and x86_64 Fedora 9 (just updated this morning, June 19).

When you've reached a directory using a symlink and then use ".." from within that tree, the interpretation of ".." is different depending on the command. See the following example:

[bnorman@localhost level1]$ ls -lR
total 4
drwxrwxr-x 3 bnorman bnorman 4096 2008-06-19 08:37 level2
lrwxrwxrwx 1 bnorman bnorman 13 2008-06-19 08:38 link3 -> level2/level3

total 4
drwxrwxr-x 2 bnorman bnorman 4096 2008-06-19 08:37 level3

total 0
[bnorman@localhost level1]$ cd link3
[bnorman@localhost link3]$ ls ..
[bnorman@localhost link3]$ cd .. ; ls ; cd -
level2 link3
[bnorman@localhost link3]$ ls '..'
[bnorman@localhost link3]$ cd '..' ; ls ; cd -
level2 link3
[bnorman@localhost link3]$

So as an argument to ls, ".." follows the true directory structure. As an argument to "cd", it follows the symbolic path that was used to get to the current directory. gcc unfortunately also follows the true directory structure when parsing include and library paths, as well.

I know this is not a gcc or ls problem per se; what library do they use to parse paths? The problem is the same under bash or tcsh. It is also the same on ext3 or ntfs partitions. Any suggestions?

EDIT: "cd" is a shell builtin, and "ls" is a binary.