[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Symbolic links and ls



On Sep 01, Martin Bartlett wrote:
> 
> Try this with RH 6.
> 
> Make a symbolic link in one directory to another in another hierarchy.
> 
> cd to the symbolic link.
> 
> do 'ls ..' and you get the contents of the REAL parent directory
> do 'cd ..' and you get back to the parent directory of the sym-link
> 
> This is inconsistent, no? the cd performs correctly and the ls
> incorrectly, no?
> 
> Or where am I going wrong?

Yes, it seems inconsistent, but it's actually "cd" which is incorrect.

".." is a file.  It has a descriptor and it exists in the filesystem.
Therefore, when you do "ls ..", you are asking for a listing of the file "..".
".." is not relative.

"cd", on the other hand, is handled by the shell you are using.  Most shells
will keep track of you current path on its own, so when you request "cd .." it
will chop off the last directory of your path and go there.  To be completely
consistent, it should change into the same directory which ls listed.  But,
the reality is that most users, when they type "cd .." want to back up in
their path, not go to the directory "..".

Now, one could argue that the same is true of "ls ..", but since "ls" is an
executable, not a builtin shell command, it is up to the ls executable to
change the behavior.  You are welcome to rewrite it, though, to let ls .. list
the previous entry in the path...

-Michael

-- 
No, my friend, the way to have good and safe government, is not to trust it
all to one, but to divide it among the many, distributing to every one exactly
the functions he is competent to.  It is by dividing and subdividing these
republics from the national one down through all its subordinations, until it
ends in the administration of every man's farm by himself; by placing under
every one what his own eye may superintend, that all will be done for the
best.
                -- Thomas Jefferson, to Joseph Cabell, 1816



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]