PDA

View Full Version : Alias How-To


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

Harold
05-10-2006, 09:46 PM
alias ls='ls --color=auto'
alias lsa='ls -a'
alias ll='ls -l'
alias lla='ll -a'

alias apt-file='sudo apt-file'
alias apt-get='sudo apt-get'
alias chmod='sudo chmod'
alias chown='sudo chown'
alias dpkg='sudo dpkg'
alias dpkg-reconfigure='sudo dpkg-reconfigure'
alias dselect='sudo dselect --expert'
alias halt='sudo halt'
alias locate='sudo locate'
alias ntpdate='sudo ntpdate north-america.pool.ntp.org'
alias orphaner='sudo orphaner --purge'
alias reboot='sudo reboot'
alias updatedb='sudo updatedb'
alias vim='sudo vim'
alias which='sudo which'

alias aconfig='./configure --prefix=/usr &> configlog.txt && vim configlog.txt'
alias debcrunch='cd /deb_packages && apt-ftparchive packages . | gzip > Packages.gz && apt-get update'
alias search='apt-cache --names-only search'
alias show='apt-cache show'
alias update='apt-get update && apt-get dist-upgrade'

alias sf='xinit /usr/bin/startfluxbox'
alias sg='xinit /usr/bin/gnome-session'
alias sk='xinit /usr/bin/startkde'
alias sw='xinit /usr/bin/wmaker'