Saturday, January 1, 2011

alias command

It can be used as an alias(short form) of a command or command with options and arguments.The alias command can be useful if you want to create a 'shortcut' to a command.


Simple examples:

1) alias ls=ls -l
In this case when we give the command ls on terminal it gives the output of ls -l (ie ls with option -l)
2) alias copy="cp /source/path /destination/path"
In this case when we give the copy alias name on terminal it will copy file from predefined source to destination
3)alias disk="df -h"
It will give the output of disk usage in human readable format when giving disk alias rather than df -h

Syntax(Format):

alias <alias option> alias_name="command <with argumens: it is optional>"

alias [-p] [alias name=value]

              Alias with no arguments or with the -p option prints the list of aliases in the form alias name=value on standard output.
When arguments are supplied, an alias is defined for each name whose value is given.


alias options :



               -l     List the names of all readline functions.
              -p     Display readline function names and bindings in such a way that they can be re-read.
              -P     List current readline function names and bindings.
              -v     Display readline variable names and values in such a way that they can be re-read.
              -V     List current readline variable names and values.
              -s     Display readline key sequences bound to macros and the strings they output in such a way that they can be re-read.
              -S     Display readline key sequences bound to macros and the strings they output.

creation of aliases with alias command is temporary for that session. To make alias permanent you need to edit your ~/.bashrc file and add line similar to this:


alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

No comments:

Post a Comment