When you first start with any Linux distrobution, you will find many references to doing things inside a terminal or console.

Even when almost everything can be done with a nice GUI, there may be some reasons to use a terminal, including efficiency.
For instance, I hate when I download a deb file from an outside source that it starts up the Software Center, or going through the Software Center to add a ppa.

A lot of new users are a little uncomfortable in using the terminal and some are even scared. What this guide does, is show you the basics and how to get things done inside a terminal.

I will not be covering any advance features inside the terminal, just the basics, but there are many guides online that cover these.

Let’s get started.

Using Bash

The name for the language used inside the terminal is called Bash, and looks fairly similar to DOS, and if you have any experience with DOS, it should look fairly familiar.
There are some distinct differences and Bash is way more powerful, but it works in a similar way.

Navigation

The first thing you will want to know and is crucial in using the terminal is navigation through the different folders (called directories), without it, you are very limited to what you can do.

When you open the terminal you will be faced with something similar to this:

arthur@arthur-CR700:~$

The first bit (arthur) shows the username that is currently being used. The next bit (@arthur-CR700) shows the computer name. Considering that I am using a MSI CR700, this will make sense, although your’s may differ.
The dollar symbol ($) indicates that we are using a normal user and not root. If this is a hash (#) then beware that you are using root which is not recommended. If you are using Ubuntu, then you should not see this.

The default directory in which you start the terminal is your home folder, but for this example I want to navigate to my Downloads folder.

** Tip: When typing a directory or file name, pressing tab will complete the name or pressing it twice will list those who start with the letters typed**

We know that the Downloads directory is found in my home folder, but just to make sure we will list the folders and files in the home folder with the ‘ls’ command:

arthur@arthur-CR700:~$ ls

After having pressed enter you should be faced with a list of items which are colour coded by the type of files, for instance, directories are blue.

I have spotted the Downloads directory and now want to navigate to it. Considering I want to Change Directory, it means I have to use the ‘cd’ command followed by the directory name.

arthur@arthur-CR700:~$ cd Downloads

After having pressed enter, you should see something like this:

arthur@arthur-CR700:~/Downloads$

Do you notice how it shows ~/Downloads in between? Well the ‘~’ symbol is the symbol for your home directory, and the forward slash (/) means the directory inside it.

This means we are inside the Downloads directory. If you now use ‘ls’ again, you will notice it lists the items inside the Downloads directory.

But, what if we entered the wrong directory and want to go back to our home directory? Well we have two options: Either we simply type ‘cd’ or ‘cd ~’ since ‘~’ means home.

But what if, we then enter into a directory called ‘aaa’ and then want to go back to the directory exactly above it and not home at all?
Well this can be accomplished by using ‘cd’ followed by two dots (..). The two dots indicate one directory up.

arthur@arthur-CR700:~/Downloads/aaa$ cd ..

After which we will see this:

arthur@arthur-CR700:~/Downloads$

Great! But if you already know the directory you wish to go into and want to got there directly, we can also skip all these steps by using ‘cd’ followed by the directory list, for instance:

arthur@arthur-CR700:~/Downloads$ cd aaa/bbb/ccc/ddd

After which we see this:

arthur@arthur-CR700:~/Downloads/aaa/bbb/ccc/ddd$

That is how you change directories

Creating a new directory

Inside the Downloads directory we want to create a new directory call ‘abc’. Well this can be done with the ‘mkdir’ command (MaKe DIRectory) like this:

arthur@arthur-CR700:~/Downloads$ mkdir abc

This will have created a directory called abc

Opening programs inside the terminal

You might be wondering what the point is in opening a program using the terminal.
Well, if you tried to open a program but it never opens, there most likely is a problem, by opening it into a terminal, it will at least give you some idea why it didn’t open.

To open the program you wish to open, you simply type the name of the program and hit enter, for Firefox, you type ‘firefox’ and it will open, just like that.

Sometimes though, it may need to have super-user powers to be used such as apt-get (more on that later).
For that, there are two options and they are for terminal applications and GUI applications

(GNOME/Unity Only)

First there is sudo – This opens an application in super-user but is recommended for terminal applications only.
Second there is gksu – This opens a GUI application.

You use it as followed:

First we will use sudo for apt-get:

sudo apt-get <command>

Considering that apt-get is a terminal program without GUI, we use sudo.

Next we want to open gedit (notepad) with super-user (it doesnt need super user but I will use it as an example).
Since gedit is a GUI application, we will use gksu:

gksu gedit

For both you will be asked for your password.

Installing applications through apt-get

You might not want to use Ubuntu Software Center to install an application and just want to use the terminal, then you need apt-get.

Apt-get can install, delete applications, add repositories, and much more, but we will only cover installing and deleting applications.

First you need to know the package name, I am going to use Firefox for this example where the package is ‘firefox’.

Apt-get will find the package, install all the needed files for it, then download and install the application.

You would install it by this:

sudo apt-get install firefox

As we have already learned, sudo will use super-user since it needs it, apt-get is the application name, install is the command and firefox the application we want to install.
After having typed this you will see that it loads the database, and then install the package, you don’t need to do anything else but wait until it’s done.

But what about deleting Firefox? It’s a case of replacing ‘install’ with ‘delete’:

sudo apt-get delete firefox

That’s all for now

So this is not an extensive tutorial, but it’s enough to make you feel a little more comfortable.

One thing to remember is that you should only use sudo or gksu when you know EXACTLY what you are doing, it doesn’t ask a password for nothing.

There will be a part 2 soon, but for now, I hope this helps

Advertisements