www.LinuxHowtos.org

edit this article

Alias, Setting command aliases

The alias command allows you to make new shortcuts and synonyms for commonly used comands. The basic usage is:

alias newcommand='yourcommand -arguments'

If you want to start aterm according to your preferences with the command term, do something like:

alias term='aterm -ls -fg gray -bg black'

If you want a quick alias like ll for a more informative file listing:

ls -al --color=yes

Starting alias without any options lists the current aliases:

alias

alias ls='ll'  
alias ls -al --color=yes  
alias term='aterm -ls -fg gray -bg black'

Use unalias to remove an alias.

unalias term

You can also make aliases for existing commands. If you want ls to show colors by default, do:

alias ls='ls --color=yes'

These aliases can be put in your login script (.bash_profile or .profile depending on what shell you are using).

Alias with variables

You can not make aliases with variables. But you can make functions, having a function in your .profile/.bashrc will work just like an alias. To use ssh to copy files to a location on a server you can use

sendpic () { scp "$@" mina@foo.bar.ca:/www/misc/Pictures/; }

Another way for aliases with variables

If you dont like to use a function, if you need variables, try the following to change to the last working directory:

alias cdo="cd \"\$OLDPWD\""

Note: it is important, that there are ONLY double quotes in the expression above, no single quotes like in the other examples!

Creating aliases on shell startup

You can have your aliases created anytime you open an instance of a shell. If you are using bash, edit your ~/.bashrc file and add one alias per line. Once you save and close the file, run this to load your new aliases immediately:

source ~/.bashrc

Otherwise, the new aliases will load whenever you open a new instance of the shell.

Another place to put your aliases if you want them to be system-wide for all users is in /etc/bashrc. To load those aliases, add this line to ~/.bashrc

source /etc/bashrc

From gentoo-wiki.com


rate this article:
current rating: average rating: 1.2 (1370 votes) (1=very good 6=terrible)
Your rating:
Very good (1) Good (2) ok (3) average (4) bad (5) terrible (6)

back