Learning Some Linux

This is a pair exercise and must be competed in your tutorial or lab with your partner.

Note that the following instructions assume that you are using text commands inside a Linux terminal window. Some of the steps (e.g. creating a new directory) can also be completed using the graphical file browser, similar to what you are used to from Windows.

Although there are lots of things you can do by using the graphical user interface (GUI) - clicking on menu items and icons, we really want you understand how to use the Linux command-line.

If you get stuck with any of this, don’t hesitate to ask one of your tutors for help, that’s why they’re here!

If there isn’t a terminal open, right click on the desktop and select ‘Open Terminal Here’; this will bring up a window where you can type in Linux commands.

There are a few commands that you can use to check your account details:

Each of these is a command, and when entering into your terminal, you need to press enter (or return) after each command. Try entering the two commands above into your terminal and see what happens.

Now try running the command date - which prints the current time and date. You should see something like this:

$ date
Mon Jul 24 12:48:10 AEST 2017

Now we’re going to learn about some commands for working with directories (directories are often called folders on other operating systems).

Current Working Directory

pwd tells you what directory you’re in, often called your current working directory.

If your username is ‘z7654321’, and you enter the pwd command into the terminal, it might tell you:

$ pwd
/import/cage/1/z7654321/Desktop

What does pwd print for you?

Listing Directories

The Linux command ls prints a list of the files in the present directory. Since you have a new account there will probably be nothing in your Desktop directory.

$ ls

Changing Directories

The Linux command cd is a command that you can use to change your directory.

If you type in cd on its own as follows, you will move into your home directory. Try this out and confirm your directory has changed by running pwd again.

$ pwd
/import/cage/1/z7654321/Desktop
$ cd
$ pwd
/import/cage/1/z7654321

If you run ls you’ll see what is in your home directory. Since you have a new account, your home directory will most likely only contain your Desktop and a directory called public_html (which is where you can create files to create websites).

$ ls
Desktop public_html

Creating Directories

The Linux command mkdir makes a new directory. To use it you must supply the name of the directory you wish to create. Lets use it to create a directory for this week’s lab exercises.

$ mkdir lab01

Now the command ls should show you the directory you just created.

$ ls
Desktop lab01 public_html

Now we will use cd in a slightly different way where we tell it what directory we want to change into.

$ cd lab01

To confirm we really are in our new created lab01 directory type the pwd command again.

$ pwd
/import/cage/1/z7654321/lab01

If all this has worked, it’s time to try compiling your first program!