temporaryhttp://www.maclife.com/taxonomy/term/12791/all
enTerminal 101: Creating Aliases for Commandshttp://www.maclife.com/article/columns/terminal_101_creating_aliases_commands
<!--paging_filter--><p><em><img src="/files/u12635/terminal_101_teaser_26.png" width="150" height="150" class="graphic-right" /></em><em>Every Monday (or in this case, Tuesday), we'll show you how to do something new and simple with Apple's built-in command line application. You don't need any fancy software, or a knowledge of coding to do any of these. All you need is a keyboard to type 'em out!</em></p><p>While using Terminal, you may discover that you constantly run a string of commands so often, it's ridiculous that you have to type them in at all. Well, just as you can create shortcuts to applications and automate actions in OS X, you can also do so for Terminal commands that are in constant rotation. These are called aliases, and you can set them up to run temporarily or permanently through your Mac’s command line interface.</p><h3>Creating a Temporary Alias</h3><p><a class="thickbox" href="/files/u12635/alias_1.png"><img src="/files/u12635/alias_1.png" width="620" height="435" class="thickbox" /></a></p><p>To create a temporary alias that is good for the current terminal session, you will use the following format to create the alias:</p><pre>alias new_name='command to be performed'</pre><p>Just about any command can be used to create an alias, but we'll use this sample command throughout this how to. This command will let us jump to our Documents folder just by typing in "documents":</p><pre>alias documents='cd ~/Documents'</pre><p>Once the command has been assigned to its alias, you can type in the alias name followed by the enter key to perform the action assigned to the alias.</p><p><a class="thickbox" href="/files/u12635/alias_2.png"><img src="/files/u12635/alias_2.png" width="620" height="435" class="thickbox" /></a><br />Note: When creating the alias, the equal sign (=) must not have a space on either side of the assignment statement. The only space should be between “alias” and the name of the new command. The name of the new command should not contain any spaces either. If you need to separate multiple words in the alias name, use underscores (_) instead of spaces.</p><h3>Recording Aliases Permanently</h3><p><a class="thickbox" href="/files/u12635/alias_3.png"><img src="/files/u12635/alias_3.png" width="620" height="435" class="thickbox" /></a></p><p>If you assign an alias using the above method, then it will only be available for the current terminal session. Once you close the terminal window, the alias will no longer be available. To make the alias permanent, you will need to edit a file called “.bash_profile” by running the following command:</p><pre>nano ~/.bash_profile</pre><p><a class="thickbox" href="/files/u12635/alias_4.png"><img src="/files/u12635/alias_4.png" width="620" height="435" class="thickbox" /></a></p><p>This will open nano (a command line text editor). Use the arrow keys to place the cursor at the bottom of the file, and type in the aliases that you wish to use, one per line, just as you did when creating temporary aliases. When you are done, press Control + O (Write Out) to save the file. Press Command + X to exit nano and go back to the command line.</p><p>When you quit and re-open the Terminal application, your aliases will work without having to re-create them each time. <br /><em><br />Cory Bohon is a freelance technology writer, indie Mac and iOS developer, and amateur photographer. Follow this article's author, <a href="http://twitter.com/coryb" target="_blank">Cory Bohon on Twitter</a>.</em></p>http://www.maclife.com/article/columns/terminal_101_creating_aliases_commands#comments.bash_profile.bash_rcaliasesColumnsMacpermanenttemporaryTerminalTerminal 101MacTue, 04 Sep 2012 17:40:05 +0000Cory Bohon14958 at http://www.maclife.com