ALIASES
To make your commandline experiences even more fun then they are already, here is a tip every lazy Linux user will love.
For long and complicated commands we can set an alias, that way an often repeated command can be brought back to one or two characters.
There are only a few rules you have to take in account: the alias comes always directly after the prompt and if you want to use more of them in one line you´ll have to add a space as you set the alias.
O.K. lets first set up some example files and directories:
NOTE: you will see the full prompt "bruno:~$" in these commands because in this case it is needed to show you how it works.
CODE |
bruno:~$ mkdir -p ~/downloads/programs/extra/ |
( Will make a directory /extra in /home/bruno/downloads/programs, we use the -p argument in order to make all the underlying directories as well if they do not already exist. )
CODE |
bruno:~$ vi ~/downloads/programs/extra/index |
( Make a textfile called ¨index¨ where we will write a simple text: )
i ( to put vi in insert mode ) and type the line:
¨This is an index of downloaded programs¨
Esc + ZZ ( to save the file )
Good, the example files are created, now the real fun starts, we set up the aliases first:
CODE |
bruno:~$ alias c='cd ' |
( Note the space after cd !!!
This is because you can only use 2 aliases one after the other if you have that space ! )
CODE |
bruno:~$ alias dp='~/downloads/programs/extra' |
Now we will use the aliases:
( so these are the alias for the command; cd /home/bruno/downloads/programs/extra )
And the proof that c dp actually worked, here is the new prompt:
CODE |
bruno:~/downloads/programs/extra$ |
CODE |
bruno:~/downloads/programs/extra$ ls |
( lets see what is in that directory )
QUOTE (Text @ Screen) |
index |
We make another alias, note the space after cat !
CODE |
bruno:~/downloads/programs/extra$ alias s='cat ' |
CODE |
bruno:~/downloads/programs/extra$ s index |
( short for ¨cat index¨ )
QUOTE (Text @ Screen) |
This is an index of downloaded programs |
( and that was the line we typed in the file )
We use the c alias again:
CODE |
bruno:~/downloads/programs/extra$ c ~ |
( will put you back where we started )
CODE |
bruno:~$ rm -rf ~/downloads/programs |
( will remove the remains of our little test, but leaves the directory downloads as it was before the test )
CODE |
bruno:~$ unalias c dp s |
( will undo the aliases we made here above )
NOTE: these aliases will only be there for as long as you do not log-out ! If you want to use them on a permanent basis you can write them in in /home/bruno/.bashrc ( clever if you have to use the same long commands every day ).
IMPORTANT: You can do "alias -p" to see what aliases are already set on your system, so you won't use ( overwrite ) one that is already in use !!

Bruno
-- Jun 8 2003 ( Revised Dec 10 2005 ) --