Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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