8

So I'm having a problem creating a shortcut to a deep folder. None of the examples I've seen on Superuser have helped :(

This is my path: cd / Applications / MAMP / htdocs / whoat / solr / whoat

I would like to create the shortcut solr to reach that directory

I have to use cd / to get into my computer from the desktop, because I can't navigate into my Applications folder otherwise.


UPDATE

I was able to get into my .bash_profile via VIM

sudo vi ~/.bash_profile

This is what I currently have inside of it, I added the last 3 lines, however none of the shortcuts work:

export PATH="/usr/local/bin:$PATH:/usr/local/share/python"
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/mysql/lib"
alias sublime="/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl"
alias edit="/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl"
alias solr="/Applications/MAMP/htdocs/website/WhoAt/solr/whoat/"

When I type solr enter, or sublime enter, nothing happens

2
  • Could the downvote explain himself?
    – Leon Gaban
    Jun 11, 2013 at 13:26
  • You question shows zero research. A quick google could have told you what the ~/.bash_profile is, let alone the other questions to asked. On that note, you asked multiple unrelated questions in the same Question.
    – demure
    Jun 11, 2013 at 13:36

2 Answers 2

10

Here is defined an alias solr which will cd to the named directory-:

alias solr='cd /Applications/MAMP/htdocs/whoat/solr/whoat'

Note the use of single quotes - double quotes will cause the cd to go to to the home directory.

I sometimes prefer to add a pwd to the alias as a check and reminder of what the current working directory is-:

alias solr='cd /Applications/MAMP/htdocs/whoat/solr/whoat;pwd'

Ideally you would put this alias in your .bash_profile in your home directory. You can use a text editor such as TextEdit or vim to add the alias command to .bash_profile. Then to load the new alias into your shell type-:

source .bash_profile
8
  • I put that into my bash_profile, and when I run just solr nothing happens. I don't get an error message however, just nothing happens. When I do LS I see my main Mac directory
    – Leon Gaban
    Jun 11, 2013 at 13:32
  • 1
    Don't forget to source the revised .bash_profile - see edited answer. Also the spacing in the path - I've removed that now in my answer.
    – suspectus
    Jun 11, 2013 at 13:35
  • if you are still having problems try setting the alias direct to the shell. Add the pwd as a check (see above).
    – suspectus
    Jun 11, 2013 at 13:45
  • 1
    ok. First enter in command line this-: alias solr='cd /Applications/MAMP/htdocs/whoat/solr/whoat;pwd'. Then if no error type solr. That should put you in the correct directory. If that works, then type cd to get to home dir. Then type source .bash_history. Does that help?
    – suspectus
    Jun 11, 2013 at 13:59
  • 2
    Excellent. Also, I believe the problem with the aliases in .bash_profile are the double quotes. Try changing those to single quotes - the shell gets confused with the spacing after the cd otherwise.
    – suspectus
    Jun 11, 2013 at 14:11
5

Links

To create links, you use the ln command. See man ln.
You could do it like ln -s /Applications/MAMP/htdocs/whoat/solr/whoat /where/you/want/link, where:

  • The first path is what you are linking
  • The second path is where the link will be

Directory Navigation

man cd

There are two ways to navigate with cd, absolute and relative.
The easiest way to get from home to applications is cd /Applications/

  • Capitalization matters....

Editing Files

Doing ~/.bash_profile isn't how you edit a file.... you were trying to run the file like it was a script (even though it a config file) Also, here is a decent article on the difference between ~/.bashrc and ~/.bash_profile

If you want to edit it from terminal, you have to use an editor, like vim/emacs/pico etc.

  • vim ~/.bash_profile
  • emacs ~/.bash_profile
  • pico ~/.bash_profile

Editing on Mac

As you are on OS X, you could use open -e ~/.bash_profile to open with TextEditor

  • Don't use sudo!

Sudo

You shouldn't be using sudo to try to 'force edit' you user's files.

  • It can mess up a file's permissions to be root's
  • It can lead to damaging accidents when you don't know what you are doing (so you should avoid it)
  • Just because you were doing it wrong, doesn't make sudo a magic wand to fix commands.

In Conclusion

Please read a few unix tutorials...

1
  • Thanks for the really detailed answer, I still could not get the shortcut to work, even after editing my .bash_profile... the command just won't work unless I just directly type in 'alias solr='cd /Applications/MAMP/htdocs/whoat/solr/whoat;pwd' then the shortcut. I can just save that in a note file. I will now proceed to watch some Unix tutorials +1
    – Leon Gaban
    Jun 11, 2013 at 14:04

You must log in to answer this question.

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