On a UNIX machine I in my current directory I create a symbolic link:
> ln -s public_html/code/index.html
Which creates a file locally named index.html
. How can cd
to the directory public_html/code
from the soft link file?
On a UNIX machine I in my current directory I create a symbolic link:
> ln -s public_html/code/index.html
Which creates a file locally named index.html
. How can cd
to the directory public_html/code
from the soft link file?
In a sh
-like environment:
cd $(dirname $(readlink -f path/to/link))
you can put it in a function:
function cdl { cd $(dirname $(readlink -f "$1")) }
This would work.
cd_link ()
{
LINK="$1";
[ ! -L "$LINK" ] && return;
DIR=$(readlink "$LINK");
DIR=${DIR%/*};
cd $DIR
}
This needs to be a function, not a script. Put in your .bashrc, .kshrc, etc.