0

This question already has an answer here:

In my home directory, I have a folder named symlinks in which all my symlinks live. I've added this folder to my CDPATH, so that I can do:

~$ cd FarAwayDirectory
~/symlinks/FarAwayDirectory$

I’ve noticed that if I pwd, I get:

~/symlinks/FarAwayDirectory -> A

rather than:

.../.../.../FarAwayDirectory -> B

which is what I would've gotten through consecutive cd’s.

So my question is: Is working in directory A identical to working in directory B?

marked as duplicate by muru, andcoz, schily, thrig, slm Jul 19 '18 at 14:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Yes. Working in directory A is the same as working in directory B.

A symlink is a special file that points to another file. ~/symlinks/FarAwayDirectory actually doesn’t have any data of it’s own (except basic file system metadata). Rather, it literally points to the directory you have it symlinked to.

You can test this by creating a file in ~/symlinks/FarAwayDirectory and confirming the file exists in the full path to the actual directory.

0

Yes, if you use the version of pwd that is built-in in bash, you'll get output A.

But try explicitly invoking a stand-alone binary version of pwd:

$ /bin/pwd

I think you'll see your output B.

Basically this is because bash remembers that you arrived to the directory through a symlink, and so presents the path to you in "logical" form (your output A) by default. If you want the "physical" path (your output B) to be presented in all cases like this, you can use set -P to make it so.

Or if you want to do it in case-by-case basis, bash's built-in cd command also supports the '-L' and '-P' options.

0

There is no directory A.

It is a symbolic link, not a directory. The working directory is the same single directory in both cases. The only difference is in the value of the PWD variable, which in turn affects what some commands report as the name of the current directory. The built-in pwd command in several shells, for example, will report the value of the PWD shell variable unless told to ignore it. The external pwd command (if told to do so with the -L option) will check that the value of the PWD environment variable that it has inherited, and if it checks out as a name for the current directory also uses it.

Further reading

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