bhobjj
05-10-2006, 08:54 PM
Alias How-To
alias is a way for you to define shortcuts for commands and paths.
Why do I need it?
1. Safety
I'm not exactly perfect. When I use 'rm' and 'mv', I want to be prompted before I really screw up.
If I am sure of what I am doing, I can always override the aliased command (rm -f).
2. Convenience
I am tired of typing "apt-get update && apt-get upgrade"
3. Tons of customization
Use your imagination.
Many distros setup aliases for you as part of the installation process.
You can list your aliases:
$ alias
I get this:
alias l='ls -lA'
alias la='ls -A'
alias ll='ls -l'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
If I want to add an alias just for the time that I am logged in to a shell (or simply test it out) i can do something like this:
$ alias su='echo "Hello"'
Then, if I enter the command:
$ su
this is what I get:
hello
This could be useful.
If you want to make you alias persistent, you can add it to a config file.
Most Linux users are using a bash shell.
Aliases for a user (non-login shell eg:xterm) are in the /home/username/.bashrc
Aliases for a user (login shell) are in the /home/username/.bash_profile
The my .bash_profile file points to my .bashrc file. This is what the contents of my .bash_profile file looks like:
. ~/.bashrc
System-wide aliases can be put in the /etc/ bash.bashrc
Some safety aliasis:
alias mv='mv -i'
alias rm='rm -i'
Nice shortcut to put in root .bashrc file:
alias agu='apt-get update && apt-get upgrade'
Sometimes, you may want to add something a bit more complicated.
You can add a function.
If I add this line to .bashrc
mkmp3 () { lame --preset extreme $1 `basename $1 .wav`.mp3; }
Then I can use the command:
$ mkmp3 some_wav_file.wav
to convert a .wav file to a .mp3
-BoB
alias is a way for you to define shortcuts for commands and paths.
Why do I need it?
1. Safety
I'm not exactly perfect. When I use 'rm' and 'mv', I want to be prompted before I really screw up.
If I am sure of what I am doing, I can always override the aliased command (rm -f).
2. Convenience
I am tired of typing "apt-get update && apt-get upgrade"
3. Tons of customization
Use your imagination.
Many distros setup aliases for you as part of the installation process.
You can list your aliases:
$ alias
I get this:
alias l='ls -lA'
alias la='ls -A'
alias ll='ls -l'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
If I want to add an alias just for the time that I am logged in to a shell (or simply test it out) i can do something like this:
$ alias su='echo "Hello"'
Then, if I enter the command:
$ su
this is what I get:
hello
This could be useful.
If you want to make you alias persistent, you can add it to a config file.
Most Linux users are using a bash shell.
Aliases for a user (non-login shell eg:xterm) are in the /home/username/.bashrc
Aliases for a user (login shell) are in the /home/username/.bash_profile
The my .bash_profile file points to my .bashrc file. This is what the contents of my .bash_profile file looks like:
. ~/.bashrc
System-wide aliases can be put in the /etc/ bash.bashrc
Some safety aliasis:
alias mv='mv -i'
alias rm='rm -i'
Nice shortcut to put in root .bashrc file:
alias agu='apt-get update && apt-get upgrade'
Sometimes, you may want to add something a bit more complicated.
You can add a function.
If I add this line to .bashrc
mkmp3 () { lame --preset extreme $1 `basename $1 .wav`.mp3; }
Then I can use the command:
$ mkmp3 some_wav_file.wav
to convert a .wav file to a .mp3
-BoB