0

NOTE: This behaviour is observed via remote access using SSH.

I noticed that if I have moved into a directory using a symlink that I cannot use the .. entry in the directory listing to move back into the parent and then into subsequent directories. For example:

/DirA/SymLinkToDirB
/DirA/SomeOtherFile.txt
/DirA/DirB
/DriA/DirC

/DirA/DirB/someFile.txt

If I was currently in DirA and issued the following command: cd SymLinkToDirB then a subsequent pwd would resolve /DirA/DirB, as expected. However, the following would not work if I was currently in DirB via the symLink.

vim ../SomeOtherFile.txt, or even cd ../DirC

Further, hitting tab while using cd would normally list the directories that a user may traverse to. However, again, this behaviour one expects and observes on a local machine also does not work over SSH.

However, the following does work if we are already in DirB having gotten there via the symlink: cd ../SymLinkToDirB/, which is a rather useless action. It seems as if the symlink resides within a directory (its parent) all its own.

No doubt this has to do with how symlinks are handled in SSH What is the mechanism through which symlinks are handled via SSH that provides this behaviour?

Kenster
  • 8,620
sherrellbc
  • 839
  • 5
  • 17
  • 31

1 Answers1

1

The cd command is trying to be smart, and remember specifically how you got to the directory you are currently in, and assumes that you want to follow the same path out again.

However, once you are in the directory, other commands (like vim) will see the existing .. directory and follow it through the real file system.

What I will do sometimes is cd symlinktoDirB/../DirB/.. . Using the extra set of ..s will force cd to see the real file system path and follow it.

hymie
  • 1,276