|
-
For example, to create a simple command alias, first open your .bashrc file in your home directory using any text
editor of your choice.
-
alias del='rm -i'
This creates an alias del for the command
"rm -i" which prompts you for confirmation that you want to remove a
file before it does so.
To create a command alias that consists of a series of commands,
-
alias llm='/usr/bin/ls -Flsa $1'
This creates an alias llm for the command
"ls" with "Flsa" flags
on a user-given directory name (=$1).
Of course, you can refer to another command alias within an alias,
-
alias h=history
alias rev='h | tail -10'
The first command assigns an alias h to the
"history" command. The next
command assigns another alias rev to the
command "h | tail -10". This
takes the output from the alias h (= the
"history" command) and pipes it through the "tail" command to list the ten most
recent commands in the command history.
Here's an example for using more than one alias on the same command line,
-
alias root='cd /; '
alias slist='ls -l | head -5'
Provided the last character in the root
alias definition is a blank space (" "). Thus any argument to this alias
as also checked to see if it is an alias. If so, it is executed. Also,
notice that in the first alias definition the command ends in a ";"
(semicolon) to allow another command to follow it.
If you type these two aliases, root slist at
the command prompt, then you're changing to your system root directory
and its contents is listed in a long format with only the first five
lines of output being displayed.
|