Setting Aliases with alias

Setting Aliases with alias

Aliases are nicknames of sorts that you use to enter commands more easily. For example, if you frequently use the command mail -s "Lunch today?" deb < .signature, you could set an alias for this command and call it lunch. Then, in the future, all you have to do is type in lunch, and the result is the same as if you typed in the longer command.

To set an alias with alias:


Choose the appropriate file to edit, depending on which shell you're using.

  • zsh users should use ~/.zshrc

  • bash users should use ~/.bashrc

  • ksh users should use ~/.profile

  • csh users should use ~/.cshrc

If you don't have the appropriate file, you're welcome to use a different configuration file. Many people store all their aliases in a separate .alias file and update their standard configurations with a line that references their new .alias file.


vi .bashrc

Edit the configuration file you've selected.


alias quit = "logout"

Type alias followed by the term you want to use as the alias, =, and the command for which you're making an alias (in quotes). Here, we're setting the word quit as an alias for the system command logout, so we can type quit instead of logout (Figure 8.8).

Figure 8.8. Setting aliases can keep you from typing long names and code.


Add as many other aliases as you want. See the sidebar called Good Aliases to Set for more ideas.


Save the file and exit from the editor. See Chapter 4 for details about saving and exiting in vi and pico.


su - yourid

Start a new login shell to test out the alias.



Type alias at the shell prompt for a listing of all the aliases you have defined (Code Listing 8.23).

Code Listing 8.23. Type alias at the shell prompt to see a list of aliases you've set.

xmission> alias cd    cd !*;echo $cwd clr   clear cls   clear copy  cp -i del   rm -i delete    rm -i dir   ls -alg home  cd ~ ls    ls -F md    mkdir move  mv -i pwd   echo $cwd type  more xmission> 

Good Aliases to Set

Here are a few aliases you might find worthwhile to set on your system:

  • alias rm="rm -i" causes the system to prompt you about all deletions.

  • alias quit="logout" lets you use quit as a synonym for logout.

  • alias homepage="lynx" lets you use homepage to start the lynx browser and connect to the Raycomm home page (substitute your home page as necessary).

Or, if you're coming from a DOS background, you might find the following aliases handy:

  • alias dir="ls -l" lets you use dir to list files.

  • alias copy="cp" lets you use copy to copy files.

  • alias rename="mv" lets you use rename to move or rename files.

  • alias md="mkdir" lets you use md to make a directory.

  • alias rd="rmdir" lets you use rd to remove a directory.


  • You can put aliases in other files, but it's customary to put them in the .bashrc file (or other appropriate rc file, such as .cshrc), so they'll be set automatically when you log in, rather than having to be manually set.

  • You can also issue alias commands from the shell prompt to set aliases for the current session.

  • Be sure to make a backup copy of any configuration files you plan to change before you change them. That way, if you mess up, you still have the original file to work with.

  • For you csh users, you'll need to set aliases without using the = signjust use "alias quit logout" and you'll be set to use quit to mean logout.

Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: