2

I have a dir /var/real-dir

I've created a soft link to it like this

ln -s /var/realdir /var/virtual-dir

Having that my working directory is /var/virtual-dir, I'm searching for a way to cd to real-dir with as less typing as possible.

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
lovespring
  • 420
  • 1
  • 4
  • 14

2 Answers2

4

You can use cd -P .

Note that this only updates the PWD and OLDPWD environment variables; the kernel-level current directory remains unchanged.

Alternatively, you can use the -P option with the initial cd like cd -P /var/virtual-dir.

jilles
  • 10,509
  • 2
  • 26
  • 39
2

You can:

cd "$(readlink -f .)"

If this is too much typing, you can create a helper function in your .bashrc, like this:

function cdlink() {
    cd "$(readlink -f .)"
}

source ~/.bashrc or start a new shell and can simply type:

cdlink
hek2mgl
  • 152,036
  • 28
  • 249
  • 266