Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Possible Duplicate:
How to build a custom command with options

I want to create a terminal short that takes me to a deeply-nested folder. For example, I just want to type in "star" every time I open the terminal to take me to cd source/alpha/beta/star.

I find it hard to believe this question hasn't been asked, but I can assure you haven't found the exact step-by-step solution. If you could let me know how to, or just point me to an existing answer, I'd appreciate.

share|improve this question

marked as duplicate by Daniel Beck, Sathya Jun 19 '11 at 11:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
... unless someone remembers that, unlike in that case, aliases aren't the only possible answer here, and tells the poor questioner about the CDPATH variable. (-: –  JdeBP Jun 19 '11 at 12:16
add comment

4 Answers

You need to look at bash aliases.

Try adding the following to either your .profile or .bashrc or .bash_profile:

alias star='cd source/alpha/beta/star'

Any command-line editor (eg vi or emacs) will work, as would any text editor for the Mac. Aliases work on all Unix-like environments (SunOS, Mac OS X, Linux, AIX, etc).

Then exit Terminal, and when you restart, it should be there. (Alternatively, you can source the script file, but I've found restarting bash to be better.)

share|improve this answer
    
Can you please point out where .profile, .bashrc and .bash_profile are located? Thanks –  Paul Mason Apr 17 '13 at 22:18
    
@PaulMason - they're where they are in any *nix-like environment: in your home directory when you open your console. –  warren Apr 18 '13 at 11:37
    
Thanks @warren! –  Paul Mason Apr 18 '13 at 23:09
add comment

You want to make aliases. Here's an easy way to make an alias without having to open up the .bashrc file. Just save this script into a file called mkalias and then move it to your usr binary directory (I believe that is ~/bin for OSX). Then run chmod +x mkalias on the file. Now whenever you want to create an alias you just type: mkalias myalias='my commands'.

#!/bin/bash
# path to .bashrc, .zshrc, etc.
export RC='~/.bashrc'

if [ `expr index "${1:-0}i" =` == 0 ]; then
    echo "Usage: mkalias ALIAS=EXPRESSION
Makes alias permanent by writing to .bash_aliases contained in home directory."
else
    # Export alias
    echo 'alias '$1 >> $RC
fi

and to answer your question now, just type:

alias star='cd /path/where/you/want/to/go'
share|improve this answer
add comment

Try this applescript on for size:

do shell script "open -a Terminal.app"
tell application "Terminal"
    do script "cd /path/to/my/directory"
end tell

That should open a Terminal for you and take you into your directory. You can shortcut it to your desktop, or maybe create a shortcut for it.

share|improve this answer
add comment

Shell scripts are the normal way to get things done, but cd only affects the current shell and shell scripts invoke a new subshell in order to run. You will need to create an alias in order to affect the current shell.

alias star="cd source/alpha/beta/star"

If you add that line to ~/.bashrc then it should normally be available whenever you open the terminal.

share|improve this answer
    
how to you add to ~/.bashrc? –  keruilin Jun 19 '11 at 3:21
    
Open it in a text editor. It's a plain text file. –  Ignacio Vazquez-Abrams Jun 19 '11 at 3:26
    
The . indicates that the file is hidden, so you can enable hidden files in your finder, or ls -a to see what's there. Edit as any other text file. –  Joe Internet Jun 19 '11 at 3:35
add comment

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