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.
1. | Choose the appropriate file to edit, depending on which shell you’re using.
|
2. | vi .bashrc Edit the configuration file you’ve selected. |
3. | 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. |
4. | |
5. | Save the file and exit from the editor. See Chapter 4 for details about saving and exiting in vi and pico. |
6. | |
7. | alias Type alias at the shell prompt for a listing of all the aliases you have defined (Code Listing 8.23). |
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 SetHere are a few aliases you might find worthwhile to set on your system:
Or, if you’re coming from a DOS background, you might find the following aliases handy: |
✓ Tips
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 = sign—just use “alias quit logout” and you’ll be set to use quit to mean logout.