HaWo's Linux Introduction

Table of Contents
Basic Linux Usage
Basic Shell Scripting Using bash
Shell Script Examples
Linux Applications
Practical: Edit-Compile-Run Cycle for C Programs
Practical: Edit-Compile-Run Cycle for Java Programs
Quick Start
Local Setup
Step-by-step Login Information

This document is a general Linux introduction, with a short introduction to shell scripting as well. It covers basic Linux usage, with a focus on the command-line, and gives links to more advanced material. Exercises throughout this introduction guide the learning process. The top-level URL for this Linux Introduction is: http://www.macs.hw.ac.uk/~hwloidl/Courses/LinuxIntro/.


The main goal of this document is to provide sufficient information on basic Linux and shell scripting usage to get started on introductory exercises. By the end of the Section called Basic Linux Usage you should be able to launch commands from the command-line, compose commands using pipes, and navigate in the filesystem. By the end of the Section called Basic Shell Scripting Using bash you should be able to write basic shell scripts to perform repetitive operations.

The context of this guide are under-graduate and post-graduate courses at Heriot-Watt University, that rely on basic knowledge of Linux usage. In particular, this guide should provide sufficient context for assignments in the courses F21CN Computer Network Security and F21SC Industrial Programming. However, it should be of broader use, and it is designed for such.

How to use this document

Depending on your experience with Linux-like operating systems, there are different ways to use this document:

Experienced users may want to jump straight to the the Section called Quick Start and follow the links given there. The material in this introduction is mainly for users with little or no experience with Linux.

First of all, make sure that you have your username and password ready. You will get these at induction day. If you missed that opportunity, contact the help desk (room EMB 1.33).

Now, work through the Section called Basic Linux Usage, which takes you through the first steps of logging in and basic Linux command-line usage. By the end of this section, you should be able to launch commands from the command-line and get help on the most common activities.

Then, work through the Section called Basic Shell Scripting Using bash, which teaches you basic shell usage in bash and takes you through a couple of exercises. It starts with simple straight-line scripts, i.e. sequences of commands that are executed as if typed on the command line, and moves on to repetitive scripts, e.g. using loops and function calls.

Finally, to deepen your understanding, look at the examples in the Section called Shell Script Examples, save the examples in separate files, and execute the files as discussed. Make small changes to the scripts to modify behaviour. By the the end of this section, you should be able to write basic shell scripts, to automate repetitive processes.

For further practicals beyond the scope of this tutorial, check the section below, in particular look-up the detailed 3-part online Unix Tutorial by Information Services at Edinburgh University.

If you prefer a comprehensive textbook, covering the range of basic to advanced Linux usage, with many examples and a fairly complete command reference, check out Sobell's Linux Guide.

How to do the exercises

All exercises in this tutorial are shown in a format like this:

$ pwd
The lines starting with $ are executable commands all other lines are the output of running this command. The $ symbol stands for the prompt you see in your terminal window. To do the exercise, cut-and-paste the text after the $ symbol into your terminal window. For example, when you cut-and-paste the command pwd from the example above, you will get the current directory as a reply. Lines starting with # are comments, explaining what the commands are doing, and can be ignored. Try variants of the commands as shown in the introduction to understand what's happening in each step. Notes at various points will refer you to a more detailed treatment of individual topics.


If in the above example you got an error like

bash: $: command not found
you also pasted the $ symbol. Only paste the text after the $ symbol into your terminal window.

Other Linux tutorials

There is a lot of good introductory material on Linux around.

These are guides tailored to the Linux setup at MACS:

These are general Linux tutorials or cheat sheets (a concise collection of the most important commands):

The following resources are more detailed Linux introductions and tutorials:

Books about Linux and UNIX in general:

Structure of this document

The first section covers basic Linux usage (the Section called Basic Linux Usage). The second section is a basic introduction to shell scripting (the Section called Basic Shell Scripting Using bash). Some worked examples of more complex shell scripts are given in the Section called Shell Script Examples. For more advanced topics see the Advanced Bash-Scripting Guide by Mendel Cooper. The final section (the Section called Local Setup) contains information specific to our local setup. As an appendix, the Section called Step-by-step Login Information provides step-by-step guidance on how to login and get started with this Linux Introduction.