an alias is sort of like a one-line script. it can be used to group together like commands or shorten common ones. you can add some into your ~/.bashrc file or add them into the profile file or even the /etc/skel/.bashrc file (for new users) or you can even just use one during a shell session.
i suggest doing it in a shell session first, just to test it. then commiting it to a static location for constant adding.
i have tons of aliases in my bashrc file just because i want to use them all the time (not to mention i'm lazy). since i use sudo, i get tired of typing "sudo shutdown -h now" everytime i want to shutdown my computer, so i made an alias
alias shutdown='sudo shutdown'
that one only eliminates the need to type the word sudo
alias sd='sudo shutdown -h now'
that makes it so i just have to type "sd" to shutdown like i want
ofcourse you can get tricky with them, say you changed to a particular directory all the time (like /home/jbsnake/scripts
)? i like to use
alias scripts='cd /home/jbsnake/scripts'Important: DO NOT name an alias the same as a command that doesn't do the same thing(i.e. alias df='do something that df doesn't do')
ofcourse you can pass an alias more than one command, just use a semi-colon ( ; ) as a seperator. Syntax: alias <nameofalias>='command1;command2;etc.'
suppose instead of just changing to the best directory ever
i wanted to list the contents once i was there. i would use this alias
alias scripts='cd /home/jbsnake/scripts; ls'
if you don't like adding symbolic links within your path using neat scripts ::cough::
you can reference different files as aliases, like
as you can tell from the first couple posts i made here, you can use an alias for many monotonous things (mounting removable media). if your like me (hopefully you aren't) i never label my floppy disks, or if i do, the name is not acurate anymore
, so this alias is great when i have to search through every one
alias floppy='LAST_DIR=`pwd`; mount /dev/fd0; cd /mnt/floppy; ls'
that alias takes my current directory and stores it into a variable called "LAST_DIR", then it mounts the floppy drive, then changes to the floppy drives directory, then lists the contents. if you havn't noticed yet, aliases are very handy things to have around.