9

I have created an alias of a folder called 'htdocs alias' and when i type in terminal cd 'htdocs alias' or cd htdocs\ alias it doesnt work?

any reasons why this is happening? or any suggestions to help this?

1 Answer 1

13

Mac OS aliases are more similar to Windows shortcuts than to Unix symlinks; you can double-click them but you cannot cd into them.

This article explains how to make cd follow OS X aliases:

This is a two-part process requiring a little familiarity with gcc and bash, but I’ll try to make it as simple as possible. Firstly, you need this file: getTrueName.c. This file was created by Thos Davis and is licensed under the GPLv2. Save it anywhere, then compile it with the following command:

gcc -o getTrueName -framework Carbon getTrueName.c

This will create the ‘getTrueName’ executable in the same directory as the source. You can add it to your PATH, or just copy it directly to /usr/bin so it’s easy to access.

Interestingly, when Terminal opens a new shell, .bashrc is not executed as you might expect. Instead, under the login shell, .bash_profile is executed. So, add the following to .bash_profile in your Home directory. You might need to create it first; it isn’t there by default.

cd() {
  if [[ -f "$1" || -L "$1" ]]; then
    path=$(getTrueName "$1")
    builtin cd "$path"
  else
    builtin cd "$@"
  fi
}

[edited the function a bit –grawity]

7
  • Alternatively, it's quite easy to create an OS X Service that creates symlinks and can be assigned the keyboard shortcut Cmd-L instead.
    – Daniel Beck
    Mar 6, 2011 at 21:15
  • The linked article no longer exists.
    – Chris Page
    Jun 14, 2012 at 23:23
  • Fixed, @ChrisPage. Jun 15, 2012 at 12:03
  • Are you sure == works? Shouldn't it be -eq? ${#1} also doesn't look right, $# should suffice...
    – Daniel Beck
    Aug 30, 2012 at 9:44
  • @DanielBeck: I just quoted the entire article, hadn't really looked into the wrapper function. Aug 30, 2012 at 12:31

You must log in to answer this question.

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