5

It seems that for many basic functions operating on symbolic links, the physical path is used by default. However, cd works fine. When moving into a symbolic link, cd remembers where I came from so it is utilizing the logical address for the symbolic link (see related post for an example: symlinks and cd).

Functions like ls only partially work this way. If I list the directory contents by hitting tab ($ ls ../ {tab}) it will list the contents of the directory where the symbolic link is located but if execute the command ($ ls ../ {enter}) the directory contents listing is from the physical path. Is there a way to get commands like ls, mv, rm, etc to operate like cd and remember the logical path for the symbolic link?

Thanks for any advice.

1 Answer 1

8

It is the shell that is providing the illusion that a symlink pointing to a directory is a real directory rooted at the location of the symlink. cd is by necessity a shell builtin, and tab-completion is also a function performed by the shell. Since cd is performed by the shell it knows about the symlink and can maintain the illusion. Most Unix commands are not implemented by the shell and thus have no way of knowing that you traversed a symlink to reach the current directory. Since these commands (ls, mv, rm, etc.) can't know about the symlink, they can't maintain the illusion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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