Take the 2-minute tour ×

After cd .. at /, why are we still at /?


pradeep@pradeep-laptop:/> cd ..

Is there a specific reason for this behavior?

share|improve this question
add comment

migrated from stackoverflow.com Sep 8 '10 at 16:10

This question came from our site for professional and enthusiast programmers.

2 Answers

The root directory has a '.' and a '..' entry in it, and the inode number for each is the same. Traditionally, the inode number is 2; it still is on MacOS X, Linux, Solaris. So, when you do 'cd /; cd ..', you end up at the same location.

In the 1980s, there was a system called Newcastle Connection that treated networked computers as being above the root of your local computer. Thus, on such a machine, you would type:

cd /../othermachine/path/to/interesting/place

to change directory to a remote file system.

(You can find the paper via a Google search of 'Newcastle Connection' - the URL is intractable.)

share|improve this answer
add comment

The cd .. command takes you up on level in the directory structure. Since you're already at the highest level, it just leaves you at the root directory.

share|improve this answer
The other answer was good from a technical perspective, but this is the common answer I immediately thought of. I mean, what else would you expect? –  Chance Sep 8 '10 at 15:31
@Chance: "No such file or directory" doesn't come to mind? :) –  Roger Pate Sep 8 '10 at 16:09
@Roger But then there wouldn't be the invariant that every directory has a .. parent directory within it. Since the system already has to handle directories that are their own parents (consider hard-linking a directory into itself), making the root its own parent requires no new functionality or special rules, so that decision obeys the principle of least surprise. –  Tyler McHenry Sep 8 '10 at 16:21
@Tyler: once upon an æon or so ago (7th Edition Unix), root could run the link(2) system call on directories - because there wasn't a mkdir(2) system call and therefore the . and .. entries were created by a root-privileged mkdir program. However, I believe that privilege has been removed even from root these days; you cannot hard-link directories. –  Jonathan Leffler Sep 11 '10 at 13:43
add comment

Your Answer

