Create bash Alias'
A Huge Linux Timesaver
A Huge Linux Timesaver
I know this isn't a very long/large/complex tutorial but I thought a good explination of this bash command is helpful and a huge timesaver since it helped me so much while using Linux, migrating from WinXP back in the day.
Many times when using linux one will encounter using terminal, you can't avoid it. Usually, it involves typing in a command or a chain of commands in the prompt to achieve a result or effect. My memory is horrible and I find it can be difficult to remember all of the commands available, or a particular order of commands, or even the actual command itself! There are lots.
Our solution for this is a bash alias. This clever command allows you to make custom, single-word commands that when typed into terminal or a virtual console, allow other pre-set commands or string of commands to run.
Let's take an example from my previous tutorial about converting .pdf and image files to .swf movies. The command to do this can sometimes be a bit long:
$ pdf2swf -o paged_dafile.swf /usr/share/swftools/swfs/simple_viewer.swf viewport=dafile.swf
Wouldn't it be much less time consuming to just switch to a folder and type pdfswf? To make this happen we just open your .bashrc file in Gedit and add the following new line at the bottom:
alias pdfswf="$ pdf2swf -o paged_dafile.swf /usr/share/swftools/swfs/simple_viewer.swf viewport=dafile.swf"
Oh yeah! If you're unsure how to open your .bashrc file with Gedit just use this command in a terminal window first:
So, what did the alias example do? Well, the new command you want to create comes first, pdfswf. Following this is the command you would like to run. If the command has spaces in it, like the one above you have to enclose it with "quotation marks".
Now you can test if our new command works by typing pdfswf in a folder with a pdf file you want to convert to a flash slideshow labeled dafile.pdf.
You can have as many alias commands as you wish inside your .bashrc file, just remember to make a new line for each one.
Before you go all alias crazy, make sure the commands you're making up aren't already in use. There are a lot of commands that you think are available but could already be taken. Linux is a practical OS made by logical people with a similar programming mind-set. There's always cross-over somewhere.
You can check to see if a command is already taken by typing whereis followed by the command. So, to check if pdfswf is already in use before making an alias, you would type whereis pdfswf into a terminal window. If you get a listing of a folder, then you know the command is already used. If you just see the command with nothing after, then you're free to assign it!
An awesome contribution from no2pencil is this cool snippet which sets up alias commands in .profile. Awesome.