7. All That Bash
There are several shells available for Linux, but the default shell — the command-line functionality you get when you open a terminal or console — is called Bash. Bash is actually an acronym derived from the phrase Bourne Again SHell; it's a pun on the traditional UNIX shell authored by Steve Bourne.

A shell is a program that takes commands from the user and passes them to the kernel for processing. Like all the other shells in Linux, Bash is not only a great tool for the command line, but also a scripting language. Shell scripting allows you to automate tasks that in a normal way would need typing in a lot of commands.

Some other notable Linux shells include the C shell, the Korn shell (also called KSH, the default for IBM's AIX operating system), the ASH shell (ASH is useful for testing whether scripts are shell compliant), the TCSH shell (fully compatible version of the Berkeley UNIX C shell), and the new ZSH shell (which closely resembles KSH but offers many enhancements).

When you open a terminal/console, you're opening the Bash shell whose prompt typically ends with a $ and looks something like this:


(In the above example, localhost and localdomain are placeholders for the names specific to your Linux login and directory location.) A Bash prompt ends with the $ symbol when you're logged in as a standard user. (In SuSE, the Bash prompt ends with a > symbol, like DOS when you're logged in as a user.) When you're logged in a root (or "administrator"), the Bash prompt ends with the # symbol. SuSE also displays # for root.

Bash History
Here's a neat Bash-prompt trick. At a basic Bash prompt, press the up-arrow key and you'll see the last command you typed in. Press again and again to rotate through all the commands you typed previously, stored for you in Bash history.

You will only see the commands you typed in for your login, whether that's for a specific user or for root.

Here are some additional Bash tips, all of which are commands that you type at the Bash prompt:

To display a full numbered list of all stored commands, type:


To retrieve the eighth command previously entered, type:


To get the last command that started with the letter V, type:


Bash history isn't lost when you reboot or shutdown either. Clever isn't it?

Bash Shortcuts
To go along with Bash basics above, here are some basic shorthand commands:

To go back one step in the directory tree, type:

cd ..

To change to the /home/{logged in username} directory, type:

cd ~

To change to the directory of a specific user when you have more than one, type the previous command followed by the name of the user:

cd ~bruno
cd ~anna

To change the directory /home/{logged in username}/Downloads/Backgrounds, type:

cd ~/Downloads/Backgrounds

For really fast typing don't forget to use the Tab-key for auto-completion. Typing the following does the same as the previous example, a lot faster:

cd ~/D {press Tab Key} /B {press Tab key}

Bash Script
You probably know that the "rm" command removes (or deletes) a file permanently. Wouldn't it be nice if we could move it to the recycle bin with a simple command instead? You can. To do that, you can make your own command called Del with a brief script.

To build the script, open a terminal and type the following lines:

{type your root password}  (Note: you should see the # prompt)
kedit /usr/bin/del

This opens a new window in the keditor into which you should type the following script:

mv $1 ~/Desktop/Trash
#End script

The next step is to save the file using kedit's File, Save As menu command. Then, back at the Bash prompt logged in as root, type this line to make the new script executable:

chmod 0775 /usr/bin/del

Now whenever you type the del command, it will run your script. For example, if you came across the "tessst" file and you wanted to move it to the trash, you could just type this at the Bash prompt:

del tessst

That will perform the same action as:

mv tessst /home/{logged in username}/Desktop/Trash

Sure this was a very short example, a three-line script, it only holds one command, but you could add as many lines to the script as you wanted to and execute it with a simple three-letter word. If there are more commands in the script it will execute them in the order that they appear. Because /usr/bin is in your path you only have to type "del" to execute it from anywhere in the file system.

If you need to do complex commands in a certain order on a regular basis, make a little bash script, put it in your path, and give it a name that's easy to remember.

In a future installment, we'll make a simple backup script, to backup and GZip the contents of your /home directory. We'll also explore the Vi editor at a later date. Vi is often the only tool for many scripting and editing chores.