CodeSpud

Bash Command of the Day – alias

May 29, 2006

http://www.ss64.com/bash/alias.html

*alias


> help alias
alias: alias [-p] [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.
Otherwise, an alias is defined for each
NAME whose VALUE is given. A trailing space
in VALUE causes the next word to be checked for
alias substitution when the alias is expanded.
Alias returns true unless a NAME is given for
which no alias has been defined.

In non – technical terms, alias command can create a nickname to a line of words indicated by value. The nickname can either be a shorthand or a descriptive name to a series of literals, for example a common command and some parameters. in some platforms aliased commands are called macros.

how I use alias

> alias ldir=’ls -la’
– typing ldir will list all files (including hidden ones) in a long listing format.

> alias gthome=’cd ~; ldir’
– An example of squeezing multiple commands. Use semi-colon (;) to separate commands.
– Running gthome will change the working directory to the current users home directory then lists all the files in long format(ldir).

> alias taillogphp=’tail -f /var/log/php/full’
– If php logging is enabled and log file is specified as /var/log/php/full, then running tail_log_php will run tail t0 show the last lines from the file then follow (-f) it. [* more on tail on later posts]

> alias beginmysql=’service mysqld start’
– if mysql is installed and binary exists, running beginmyql will start the mysql service

There are so much more ways you can benefit with this shorthand definition command. Btw, all definitions are temporary, when you boot the system again the aliases you thougthfully constructed will go kapoot! 😉 Luckily you can make it permanent, by defining them in .bash_aliases from your home directory. Next time you boot, the ‘macros’ will be within your reach again. 😀

By @codespud  
DISCLAIMER This is my personal weblog and learning tool. The content within it is exactly that – personal. The views and opinions expressed on the posts and the comments I make on this Blog represent my own and not those of people, institutions or organisations I am affiliated with unless stated explicitly. My Blog is not affiliated with, neither does it represent the views, position or attitudes of my employer, their clients, or any of their affiliated companies.