0

I have a project with node_modules folder that contains a symbolic link to another project. The problem that inner project takes configs from parent project (etc ../../../config) and thus cannot find it because of the relative path starting from the original folder instead of a symbolic link.

Example:

$ cd ~
$ mkdir -p a/b/c
$ ln -s a/b/c d
$ cd d
$ ls ../

Will display content of b folder. But I need to display listing of ~ directory. How to do it?

  • I'm a bit confused on your question but assuming your shell is bash or ksh would ls "$OLDPWD" or ls ~- work for you? – fd0 Apr 4 at 12:09
1

Unfortunately, this is not how symbolic links work.

From the man page (man ln)

The ln utility creates a new directory entry (linked file) for the file name specified by target_file. The target_file will be created with the same file modes as the source_file. It is useful for maintaining multiple copies of a file in many places at once without using up storage for the “copies”; instead, a link “points” to the original copy.

Emphasis mine

So, how do you get around this? Use an environment variable. For example:

$ mkdir -p /a/b/c
$ FOO='/a/b/c'
$ cd ~
$ cd $FOO
$ pwd
/a/b/c

Note, you should use absolute paths when doing this; using relative paths can and will have unintended consequences.

  • Which ln man page are you quoting from. Is that an exact quote or a paraphrased quote? I'm asking because what's quoted is not what I'm finding in the man page in macOS. – user3439894 Apr 4 at 11:58
  • macOS. It's right under the DESCRIPTION headding. – Allan Apr 4 at 12:03
  • What version of macOS? – user3439894 Apr 4 at 12:07
  • Checked on High Sierra and El Capitan. – Allan Apr 4 at 12:08
  • Okay, I've looked at the ln man page in OS X El Capitan, macOS High Sierra and macOS Mojave. The paragraph you've quoted doesn't exist as quoted in all three. So is what you quoted an exact quote or a paraphrased quote? – user3439894 Apr 4 at 12:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .