The idea is to have the environment configured like this:

mkdir ~/shortcuts
cd shortcuts
ln -s ../.. up2

As a result I want to be able to go 2 directories up the file tree whenever I call:

~/dev/project/src$ CDPATH=~/shortcuts cd -P up2

I think I was able to achieve that on macOS a few weeks ago but I cannot remember how I did it (and now I'm not so sure about it any longer). Additionally, I'd like it to be portable (ideally, POSIX-compliant).

  • 1
    Alias alias cd2up='cd ../..'? – myaut Mar 10 '17 at 21:40
  • @myaut I'd prefer a solution based on a filesystem. I'm aware of the alias workaround. – Mateusz Piotrowski Mar 10 '17 at 21:45

Symlinks with relative paths as their contents are relative to the directory in which the symlink lives, not relative to the cwd of the process that resolves the symlink. The trick you are trying to achieve shouldn't be expected to work.

| improve this answer | |
  • That's what I suspected after reading some SE threads and docs online. – Mateusz Piotrowski Mar 10 '17 at 23:01
  • @MateuszPiotrowski, alias up2='cd ../..' is the clever way. Otherwise, just use cd ../.. or cd .. and !!; it's not that much typing. – Wildcard Mar 10 '17 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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