Subscribe to Penguin-man the computer guy

Friday, May 31, 2013

Getting to Know the Linux Terminal and BASH

In my first post on Linux Commands, I gave a bunch of examples on various commands but I didn't really give much background about the Terminal, the terminal environment, and the scripting language. Today when we say we are using Linux Commands most people in the field will understand that we are referring to a specific kind of scripting language that works on UNIX-like environments; specifically, this usually means BASH commands and scripts. But what is BASH, a terminal, or a terminal emulator?

In short we should get a few basics straight. Geeks are sloppy so when we say terminal we usually mean terminal emulator. When we use the terminal, the commands we type are in BASH. BASH is a far which is a far more powerful language than DOS for Windows. Because BASH is a language, we can use it to make small programs and run them from a file.

Meet the friendly Gnome-terminal :)

The Terminal 

A terminal emulator is a program that you can use to interact with the operating system. The terminal uses text based commands and can read files to allow it to control the operating system. When using a terminal, remember that it goes by several different names including these names:
Terminal
Command Line
Command Prompt

In Ubuntu if you are running the Unity desktop (Default GUI for Ubuntu 11.10 and beyond I believe) the way to access the terminal for the first time is from the Heads Up Display (HUD). To access the HUD, press the Win key or clicking on the HUD icon with the mouse:
HUD icon button at top right had side of Unity Desktop
Once the HUD launcher opens type the name of the application in the command line; here we type "terminal". Notice that it is unnecessary to type the entire name.


Click on the terminal application. This will give you the default GNOME Terminal. Once you are using the default terminal, if you right click on the terminal icon you can lock it to the launcher... do this, if you are serious about Linux you will use the terminal all the time. Note, as seen in the picture below, if you right click on the top bar of the terminal you have more options.

Is the gnome terminal the only terminal available in Ubuntu? No, there is xterm and there is terminator; xterm is used in some light weight set ups. My preference is either the gnome terminal or terminator. I actually like terminator a lot and terminator has many more features than gnome terminal. One of these features is seen below:
Terminator can be split to show several terminals at once.
Terminal's window can be split into many segments that are each there own terminal. I do enough stuff on the terminal that this is useful at times. Of course the Gnome terminal allows tabs, but terminals split feature is far more useful. To install the Terminator terminal emulator run the following in a terminal:

sudo add-apt-repository ppa:gnome-terminator
sudo apt-get update
sudo apt-get install terminator
For more information about terminator I like this article and the terminator home page. I have not used a Mac machine yet, but they too are UNIX based so you can install terminator on a Mac too.

        fink install terminator

Terminals vs. Terminal Emulators

A terminal emulator is a GUI based application; a terminal is the screen of an OS when the the GUI is not running. As we said above, geeks are often sloppy in how they talk and say run <x> in the terminal instead of being correct and saying  run <x> in the terminal emulator; so when we say terminal we usually mean terminal emulator and assume you understand. Because many servers don't have any GUI at all, we often use the "real" terminal in them, and using a terminal is much like a terminal emulator. If you are running Ubuntu, to leave the GUI and see a terminal use the keyboard shortcut cntr-alt-F1, F2, F3, F4, F5, or F6 and to return to the GUI run cntr-alt-F7. Fun, huh? It is actually a great way to rescue a crashed GUI.

BASH

Once you feel comfortable around the actual terminal itself, it is time to meet BASH. Bash is a Unix shell that was developed by the GNU project. The BASH shell replaces the Bourne Shell which in turn replaced the Thompson shell. The Bourne shell was developed in 1977 and BASH was released in June 1989. The Thompson shell that Bourne replaced was written by Ken Thompson in 1971. If your starting to realize that the BASH tradition goes back a ways, your right... it does!!! There is a ton of documentation online and I will not try to repeat that.

BASH syntax is pretty easy... the general syntax is:
        command [arguments] <file>

BASH has a few simple commands everyone should know... here are my basics
To list files, run ls:

        ls
        ls -l
        ls -a
To change directories, run cd:

     cd /media/flashdrive/anime
To change directories to home, run cd ~

    cd ~
To change directories to root, run cd /

     cd /

To change directories back one directory (towards root) run ..

     $..
To update your Ubuntu or Debian based system run:

     sudo apt-get update 
     sudo apt-get upgrade 

Or run this which does both...

    sudo apt-get update && sudo apt-get upgrade 

No comments:

Post a Comment