alias command

When working with SSH and the command line interface, you may want to begin trimming down the number of keys you hit by creating aliases for the commands you use most often. This can help you move along faster when working on your site. This article goes over the alias command and how to use it.

Command: alias
Synopsis: alias [name[=value] …]

Examples

Alias for the clear command

In this example, we create an alias for the ‘clear‘ command. We shorten it to simply ‘c‘.

 # alias c='clear'     

Aliases for various cd commands

For this example, we will make some shorter cd commands for going up one, two, or three levels.

 # alias ..='cd ..' # alias ...='cd ../..' # alias ....='cd ../../..'     

Aliases for common mistakes

If you have a habit of not leaving a space in between the ‘cd” and the ‘..’ portion of the ‘cd ..‘ command, you can create an alias for that as well.

 # alias cd..='cd ..'     

Listing the aliases

If you want to have the entire list of aliases displayed, use the following version of the alias command.

 # alias -p alias attrib='chmod' alias chdir='cd' alias copy='cp' alias cp='cp -i' alias d='dir' alias del='rm' alias deltree='rm -r'     

Removing an alias

The following couple of examples demonstrate how to remove aliases with the ‘unalias‘ command.

Removing a single alias

This example shows how to remove a single alias. In the example below we are removing the ‘c‘ alias we created above.’

 # unalias c     

Remove all aliases

If you wish to clear your alias list, use the following command. Do note that it deletes ALL aliases.

 # unalias -a     

Leave a Reply