Introduction to Linux - Research and Specialist Computing Support

Introduction to Linux - Research and Specialist Computing Support
Introduction to Linux
Research and Specialist Computing Support
V1.8 October 2015
Introduction ......................................................................................................................................................... 3
Connecting to Linux ............................................................................................................................................. 5
Files and navigation ............................................................................................................................................. 8
Getting help ....................................................................................................................................................... 11
Data transfer and management ........................................................................................................................ 13
Text and string tools .......................................................................................................................................... 15
Processes and jobs ............................................................................................................................................ 19
File permissions ................................................................................................................................................. 22
Compiling Linux software .................................................................................................................................. 24
Linux shell variables ........................................................................................................................................... 26
Editors................................................................................................................................................................ 29
What to do next................................................................................................................................................. 32
About this tutorial
This Linux tutorial is designed to provide an introduction to Linux and many of the core tools. Working through
this tutorial should leave you familiar with working on the command line interface.
The tutorial has been developed by the Research and Specialist Computing Support team, part of the
Information Services Directorate. The tutorial is based on the UNIX tutorial developed by Michael Stonebank
of the University of Surrey, available at
What is Linux?
UNIX is an operating system which was first developed in the 1960s, and has been under constant
development ever since. By operating system, we mean the suite of programs which make the computer work.
It is a stable, multi-user, multi-tasking system for servers, desktops and laptops.
Linux is the name given to UNIX like operating systems based on the Linux Kernel developed by Linus Torvalds
in 1991 (the kernel sits between the programs you want to run and the hardware of your computer). Torvalds
began developing the Linux to provide an operating system that would allow other people to contribute to its
development (unlike most previous UNIX type operating systems which were closed). This philosophy
continued and Linux became closely linked with other projects such as GNU and the Free Software Foundation,
providing a kernel, operating system and software which was free to use, distribute and modify.
Linux and UNIX systems also have a graphical user interface (GUI) similar to Microsoft Windows which provides
an easy to use environment. However, knowledge of the command line interface is required for operations
which aren't covered by a graphical program, or for when there is no windows interface available, for example,
in a secure SSH session
Linux is a powerful operating system commonly used in scientific computing, and is ideal for remote access.
Linux is becoming increasingly popular and in recent years the development of increasingly user friendly and
hardware compatible Linux distributions have led to a growth in desktop use. Linux is also receiving more
media attention thanks in part for example to the popularity of the sub £30 credit card sized computer, the
Raspberry Pi and Google’s Linux based Android operating system.
There is a very good background on the history of Linux available on Wikipedia at
Windows or Linux
Windows may have the market share on the desktop with 90% of installations, with Linux only having just over
1.7% of installs1 but there are areas where Linux is the leading Operating System:
The Apache web server, the standard for Linux/UNIX servers, accounts for over 59% of the web servers
on the Internet, compared to less than 15% for Microsoft2
In the June 2015 Top 500 Supercomputer list, 97.6% of systems ran Linux with a further 2% running
Linux at UEA
There are many different distributions of Linux available, from those designed for general purpose use, to
those designed for enterprise level stability. In between there are distributions to meet specific needs such
as multimedia, education, security or for different hardware types such as tablets or computers with very low
hardware resources. Ubuntu is perhaps the most well-known Linux distribution, though according to
download figures Mint is currently the most popular. Red Hat Enterprise Linux is the most common in
enterprise installs, for example web and email servers.
There are a number of options for those that need Linux at UEA:
For those needing occasional access to a Linux command line (CLI) interface, there is the general
purpose Linux login server
Those needing regular access to Linux, or who need to use graphical Linux applications can have the
official UEA Linux desktop installed on their UEA workstation by contacting the Research and Specialist
Computing Linux support team by emailing
If you have computationally intensive work to do, you can request an account on Grace, the UEA High
Performance Computing cluster
Ubuntu 14.04 LTS
CentOS is based on Red Hat
(Precise Pangolin) is based on
Debian, coming with long term
support until 2019. Ubuntu is the
UEA official Linux desktop OS,
integrating with central services to
provide a secure, full featured,
graphical working environment for
up to date PC and laptops.
Enterprise Linux providing a secure
and stable operating system used
at UEA for the general purpose
Linux login server RCLogin and
High Performance Computing
cluster Grace. CentOS offers a
stable command line Linux
Connecting to Linux
Before we look any further at Linux, we’ll log into a Linux system using a secure shell (SSH) connection. Linux
and UNIX based operating systems (for example, Mac OS) usually have an SSH client built in. Where this is the
case you can connect to another Linux server by typing:
In Windows we use the free tool PuTTY (which is available on UEA Windows PCs or can be downloaded from Open PuTTY and enter the name of
the system you wish to connect to in the Host Name box. For this tutorial you will be using
Make sure the Connection type is set to SSH, as shown below
When using PuTTY from most UEA computers, your UEA username will automatically be detected, and
because all systems are integrated, your credentials will be securely sent through to the remote server,
meaning you may not need to enter your password.
When connecting from non UEA systems, you will be prompted for your username and then asked to enter
your password.
Note: At the password prompt, when typing you will not see any letters or asterisks etc, this is a security
measure and is intended!
Now that we are logged in, we can look a little further at Linux. The Linux operating system is made up of a
number of parts; the kernel, the shell, filesystems and the programs.
The Kernel
The kernel in Linux is the hub of the operating system: it allocates time and memory to programs and handles
the filestore and communications in response to system calls.
As an illustration of the way that the shell and the kernel work together, suppose a user types rm myfile
(which has the effect of removing the file myfile). The shell searches the filestore for the file containing the
program rm, and then requests the kernel, through system calls, to execute the program rm on myfile. When
the process rm myfile has finished running, the shell then returns the Linux prompt to the user, indicating
that it is waiting for further commands.
The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks
the username and password, at UEA we use a tool by Quest Software called VAS which allows Linux systems
to authenticate securely with your standard UEA credentials. Once logged in the shell is started, which is a
command line interpreter (CLI). It interprets the commands the user types in and arranges for them to be
carried out. The commands are themselves programs: when they terminate, the shell gives the user another
The adept user can customise their shell, and users can use different shells on the same machine. The current
default shell is the tcsh shell, the main alternative is the bash shell.
[scs10ygu@rclogin ~]$
The default prompt should look similar to the example above. The first part displays username@hostname
followed by the directory you are in (here the tilde represents your home directory).
Both shells have certain features to help the user input commands:
Filename Completion - By typing part of the name of a command, filename or directory and pressing the
[Tab] key, the shell will complete the rest of the name automatically. If the shell finds more than one name
beginning with those letters you have typed, it will beep, prompting you to type a few more letters before
pressing the tab key again.
History - The shell keeps a list of the commands you have typed in. If you need to repeat a command, use the
 and  cursor keys to scroll up and down the list or type history for a list of previous commands.
Linux filesystems are arranged differently than Windows filesystems. All the files are grouped together in the
directory structure. The filesystem is arranged in a hierarchical structure, like an inverted tree. The top of the
hierarchy is traditionally called root (written as a slash / ).
(Image: Highlights of the filesystem tour, taken from
The whole filesystem can reside on one hard drive partition, or any directories below / can be on their own
dedicated partition of a hard drive, or mounted as a network drive.
Under each directory shown, there will be further subdirectories:
In this example, the directory /home/ contains a
number of subdirectories representing groups of
users, at UEA defined by faculty or department.
Within one there is a directory scs10ygu, my home
directory, which is where I would be placed when I
log into the Linux system.
Inside where there are various subdirectories, for
example Training, and a file List.txt. The full path for
these would be:
Files and navigation
There are a number of conventions and rules regarding the naming of files in Linux, which in particular differ
from Windows:
Linux is case sensitive, so the files Myproject, MyProject and myproject are all different.
File and directory names must be unique in a directory, so for example you can’t have a directory
called MyProject and a file called MyProject in the same directory.
While it is possible to have file or directory names with spaces in them, it is encouraged that you don’t
use spaces. You are also encouraged to avoid using any of the following characters: / \ > < | : ; , * ? &
Under Linux there is no need for file extensions, an executable file simply has the appropriate
executable permission set. File extensions can be used though for ease of use and identification, i.e.
using file.txt for text or notes, using data.csv for comma separated value files etc.
We should note here that a directory is merely a special type of file. So the rules and conventions for naming
files apply also to directories.
To find out which files are in a directory, type ls (lowercase L and lowercase S) which lists the contents of
your current working directory. There may be no files visible in your home directory, in which case, the Linux
prompt will be returned. Alternatively, there may already be some files inserted by the System Administrator
when your account was created.
ls does not, in fact, cause all the files in your home directory to be listed, but only those ones whose name
does not begin with a dot (.) Files beginning with a dot (.) are known as hidden files and usually contain
important program configuration information. Be careful when changing hidden files, altering these
configuration files can cause programs to behave differently!
The command has a number of options which will alter the displayed output, showing different file and folder
metadata. Some useful options, which can be combined to display the required information include:
-a, --all
-h, --human-readable
-r, --reverse
Do not ignore entries starting with .
Use a long listing format (lower case L)
With -l, print sizes in human readable
format (e.g., 1K 234M 2G)
Reverse order while sorting
Sort by file size
Sort by modification time
Pathnames enable you to work out where you are, in relation to the whole file-system. For example, when
you first log into Linux you will be put in your home directory - to find out the absolute pathname of your
home directory, type pwd.
[scs10ygu@rclogin ~]$ pwd
A new directory can be created with the mkdir command, for example mkdir Training will create a
directory called Training in the current working directory.
The command cd means change the current working directory to 'directory'. The current working directory
may be thought of as the directory you are in, i.e. your current position in the file-system tree. Create a
directory called Training, and change into that directory:
[scs10ygu@rclogin ~]$ mkdir Training
[scs10ygu@rclogin ~]$ cd Training/
[scs10ygu@rclogin ~/Training]$ pwd
Notice that now we have changed directory, the shell prompt has also changed to include the top level of the
current working directory. When referring to directories in Linux there are a number of shortcuts:
Previous working directory (when changing directory)
The root directory
Current directory
The parent directory (directory above the current
working directory)
Home directory
When using the cd command to change directory, the destination can either be a relative or absolute path,
for example if you are in the directory /home/stfcen6/cc/Training/example to get back to the home directory,
any of the following options could be used:
cd /home/stfcen6/cc
Absolute path to the home directory
cd ../..
Relative path, being two directories above the current directory
cd ~
Using the tilde shortcut
Just using cd on its own returns you to your home directory
Copying, moving and renaming files and directories
cp file1 file2 is the command which makes a copy of file1 in the current working directory and calls it
What we are going to do now, is to take a file stored in an open access area of the file system, and use the cp
command to copy it to your Training directory.
First, cd to your Training directory:
[scs10ygu@rclogin ~]$ cd Training/
Then at the prompt, type,
[scs10ygu@rclogin ~/Training]$ cp /rclogin/home/resources/science.txt .
The previous command means copy the file science.txt to the current directory, maintaining the same name.
Don't forget the dot . at the end. Remember, in Linux, the dot means the current directory.
To move a file or directory from one place to another, use the mv command. This has the effect of moving
rather than copying the file, so you end up with only one file rather than two. It can also be used to rename
a file, by moving the file to the same directory, but giving it a different name.
[scs10ygu@rclogin ~/Training]$ mv science.txt Science.txt
[scs10ygu@rclogin ~/Training]$ ls
Deleting files
!!!Note: generally in Linux, particularly on the command line, there is no undelete facility!!!
To delete (remove) a file, use the rm command. As an example, create a file using the touch command (the
touch command creates an empty file if the filename doesn’t exist, or updates the timestamp on a file if the
filename does exist):
ls: No
~/Training]$ touch
~/Training]$ ls
~/Training]$ rm
~/Training]$ ls
such file or directory
You can use the rmdir command to remove a directory (make sure it is empty first - you will not be able to
delete a non-empty directory:
[scs10ygu@rclogin ~/Training]$
[scs10ygu@rclogin ~/Training]$
[scs10ygu@rclogin ~/Training]$
rmdir: dirtodelete/: Directory
[scs10ygu@rclogin ~/Training]$
[scs10ygu@rclogin ~/Training]$
mkdir dirtodelete
touch dirtodelete/test
rmdir dirtodelete/
not empty
rm dirtodelete/test
rmdir dirtodelete/
Use the commands cd, ls and pwd to explore the file system (you can explore you own home
directory) Hint: Remember, if you get lost, type cd by itself to return to your home-directory
Copy all the files from /rclogin/home/resources to your own Training directory. Hint: use * as a
Getting help
Having looked at some of the more common commands, we now need to start looking beyond the basic
options for these and other commands. The information about the commands presented in this tutorial cover
the key functionality, however many of the commands provide advanced options making the tools far more
powerful. In order to identify these advanced features, you will need to read the manual for the command.
There are manuals online which provide information about most commands. The manual pages (manpage)
tell you which options a particular command can take, and how each option modifies the behaviour of the
command. Type man commandname to read the manual page for a particular command, for example man ls
User Commands
ls - list directory contents
ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort.
Mandatory arguments to long options are
-a, --all
do not ignore entries starting with .
-A, --almost-all
do not list implied . and ..
with -l, print the author of each file
You can scroll through the pages with the  and  cursor keys. To search within a manpage, press / (forward
slash) and then the word you want to search for. Finally, press q to quit from man.
Basic usage instructions can also often be found on each command by running the command with –help:
[scs10ygu@rclogin ~/Training]$ mkdir --help
Usage: mkdir [OPTION] DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
-m, --mode=MODE
set permission mode (as in chmod), not rwxrwxrwx - umask
-p, --parents
no error if existing, make parent directories as needed
-v, --verbose
print a message for each created directory
-Z, --context=CONTEXT (SELinux) set security context to CONTEXT
display this help and exit
--version output version information and exit
Report bugs to <>.
Data transfer and management
There are a number of ways of transferring data to and from Linux systems at UEA. For example, your UEA
central filestore is available when you log into a central UEA Linux system, as can be seen below:
[scs10ygu@rclogin ~/Training]$ cat data/Documents/CFSfromWindows/Windows.txt
This is a file created in Windows.
Created in Notepad and saved to UEA CFS
The easiest method for transferring data between two systems is to use the secure copy tool, scp. scp is
based on SSH, and depending on where you are copying files to and from, you may be prompted for your
credentials. scp is run in a similar way to cp with a source destination approach, but (depending on where
you are copying data to and from) one is prefixed with a remote computer name. This allows you to copy
individual files between two systems you have an account on (in this case, the other Linux system, or by using the –r flag, indicating recursive copy, and the wildcard *, you can copy
multiple files, for example:
scp –r sourcedirectory/*
The tool wget allows you to download files from http, https and ftp sites:
[scs10ygu@rclogin ~/Training]$ wget
--2012-11-10 18:52:04--
Connecting to||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 20716 (20K) [application/x-gzip]
Saving to: `example.tar.gz'
100%[======================================>] 20,716
in 0.001s
2012-11-10 18:52:04 (27.9 MB/s) - `example.tar.gz' saved [20716/20716]
Often when downloading files from the internet, the download site will provide the md5sum for the file, which
allows you to verify the download has completed correctly and ensure data consistency. On the
example.tar.gz file downloaded with wget, run md5sum example.tar.gz which should return:
[scs10ygu@rclogin ~/Training]$ md5sum example.tar.gz
8c3a0200e84533ef95c1dc2166c53869 example.tar.gz
Having confirmed the file downloaded correctly, the next step is to extract the contents of the file. Where the
predominant archive format for Windows is perhaps zip files, in Linux it is tar files. A tar file, often referred to
as a tarball, is generally a collection of other files or folders. Tar files are the standard way of distributing
source code, collections of file, and general data for Linux. By itself, a tar file is not compressed, and will be
the same size as all the individual files that make up the tar. Tar files are most often used in with either gzip
or bzip type compression. The tool for working with tar files is also called tar.
tar tvf filename.tar
tar xvf filename.tar
tar xvf filename.tar /home/cc/test.txt
tar cvf filename.tar filename
tar cvf filename.tar directory/
tar cvzf filename.tar.gz filename
tar cvzf filename.tar.gz directory/
tar cjvf filename.tar.bz2 filename
tar cjvf filename.tar.bz2 directory/
List the contents of the tar file filename.tar
Extract the contents of filename.tar (in most modern
versions of tar this will also extract gzip and bzip
compressed files)
Extract an individual file (or folder) from a tarball. Requires
the full path of the file or folder to be extracted
Create a tar file called filename.tar containing filename (or
files in directory)
Create and gzip a tar file called filename.tar.gz containing
filename (or files in directory)
Create and bzip a tar file called filename.tar.bz2 containing
filename (or files in directory)
The du command outputs the number of kilobyes used by each subdirectory. Useful if you have gone over
quota and you want to find out which directory has the most files. In your home-directory, type du –sh *
the -s flag will display only a summary (total size), the h displays in human readable format (G, M or K) and the
* means all files and directories.
This searches through the directories for files and directories with a given name, date, size, or any other
attribute you care to specify. It is a simple command but with many options - you can read the manual by
typing man find. To search recursively for the file named Science.txt (from the current working directory)
use the example shown below. If you wanted to search for all files with the extension .txt, starting at the
current directory (.) and working through all sub-directories, then printing the name of the file to the screen,
type find . -name '*.txt'
[scs10ygu@rclogin ~]$ find . -name Science.txt
To find files over 50Kb in size in the folder Training, and display the result as a long listing, type find
Training/ -size +50k –ls
Use wget to download
Check with md5sum that the download is correct (8c3a0200e84533ef95c1dc2166c53869)
Extract and uncompress example.tar.gz in your Training directory
Text and string tools
There are a number of tools which allow you to view, extract information and manipulate text and data files
in the console.
more and less
The command more filename will display the contents of filename one screen at a time, using the [Space
Bar] to navigate to the next page. A similar command to more is less filename which again displays the
contents of the file page by page with the [Space Bar], but also allows you to navigate up and down using
the  and  cursor keys. Both tools allow you to search the file by pressing / followed by the text you want
to search for and [Return]. Subsequent searches for the same phrase can be done by typing / followed by
[Return]. To quit from either, press q.
head and tail
Two further commands that display the contents of a file are head filename and tail filename. As their
names suggest, these commands display the top and bottom of the file respectively. Showing 10 lines by
default, this can be modified with the –n flag to display a set number of lines:
[scs10ygu@rclogin ~/Training]$ tail –n3 lorem.txt
felis. Pellentesque sit amet nulla ipsum. Sed hendrerit libero eu dui
auctor lobortis. Morbi adipiscing aliquet sem eu tincidunt. Cum sociis
natoque penatibus et magnis dis orci aliquam.
While head and tail can be used to show a number of lines in a file, the command wc with the –l (lower case
L) option will report on the number of lines in a file:
[scs10ygu@rclogin ~/Training]$ wc -l lorem.txt
1192 lorem.txt
Redirects and pipes
Another command to output the contents of a file is cat which, unlike more or less, rather than displaying the
contents screen by screen, just outputs the whole file and returns you to a prompt. The command cat
filename is most useful when combined with other commands, which is done using a pipe. Pipes take the
output from one command directly to the input of another command. The symbol for a pipe is the vertical
bar |
An example of pipe in action is to use the cat command with the grep command. The grep command allows
you to search within a file for specific words or patterns. As an example, there is one line in lorem.txt that
contains the word English. Rather than searching through lorem.txt line by line (all 1193 of them) grep quickly
searches the file. If we use cat to output the file into the grep command, it will search for the word English:
[scs10ygu@rclogin ~/Training]$ cat lorem.txt | grep English
lectus. There is one statement in this document in English. Donec velit
We can use grep independently of cat, by running grep English lorem.txt for example. Also, grep
can use wildcards, so we could search for the word English in ALL files by using the command grep English
* and further to this, combined with the –r flag (recursive) grep will also search all subdirectories for the
pattern. Grep can also be used to display lines that do not match, -v flag: grep –v English lorem.txt
or ignore the case of the search, -i flag, for example grep –i english lorem.txt would pick out any
occurrences of english, English or ENGLISH etc.
The output of a command can be redirected into a file by using > for example:
[scs10ygu@rclogin ~/Training]$ cat lorem.txt | grep English > justEnglish.txt
[scs10ygu@rclogin ~/Training]$ cat justEnglish.txt
lectus. There is one statement in this document in English. Donec velit
Using a single chevron redirects the output to create a new file; if the file already exists, its contents are
overwritten. If double chevrons are used, the output is appended to the end of the file if the file already exists,
for example cat lorem.txt | grep English >> justEnglish.txt
Utilising pipes and redirects allows multiple commands to be chained together to make working with data
easier. An example of this is using the sort command, which is used to sort the contents of a file in various
ways. The file sales.csv contains comma separated values data and can be sorted so that the sales areas are
in alphabetical order with the command sort sales.csv. However, this will result in the header row
being included in the sort. Using some of the previously documented commands, for example finding out how
many lines there are in the file (wc –l) combined with the tail command me, it is possible to remove this line
before sorting the file:
[scs10ygu@rclogin ~/Training]$ cat sales.csv
Sales Area,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
[scs10ygu@rclogin ~/Training]$ wc -l sales.csv
7 sales.csv
[scs10ygu@rclogin ~/Training]$ tail -n6 sales.csv | sort
sed and awk
Two of the most powerful Linux command line tools are sed and awk. These tools allow much more complex
data processing than other Linux commands. At its most basic, sed provides useful string replacement
functionality. The following command shows sed substitution in action:
[scs10ygu@rclogin ~/Training]$ cat lorem.txt | sed 's/is one statement/are two
statements/g' | grep English
lectus. There are two statements in this document in English. Donec velit
Firstly the text in lorem.txt is piped into the sed command; at which point sed is substituting the phrase “is
one statement” with “are two statements”. The sed command is broken down by the forward slash: in the
first field the s indicates sed is being used to substitute text; in the final field the g indicates this is a global
change, meaning all matching instances of the search in the file will be changed. This is only a basic example
of sed, there are far more complex examples for more advanced usage. There are plenty of good guides for
sed available on the internet.
Useful modifiers for sed (and grep) include the caret (^) which indicates the start of the line and $ which
indicates the end of the lines, so ^M would only match lines starting with M, and 5$ would only match lines
ending with 5:
[scs10ygu@rclogin ~/Training]$ grep M sales.csv
Sales Area,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
[scs10ygu@rclogin ~/Training]$ grep ^M sales.csv
[scs10ygu@rclogin ~/Training]$ grep 5 sales.csv
[scs10ygu@rclogin ~/Training]$ grep 5$ sales.csv
The contents of two files can be compared using the command diff file1 file2. This command
compares two files and displays the differences. If we take lorem.txt, and use sed to modify some of the text
(sed can create a backup of the original file using the –i.bak command option, where .bak is the file extension
of your choice). We can compare the original and new file to confirm the differences:
[scs10ygu@rclogin ~/Training]$ sed -i.bak 's/is one statement/are two statements/g'
[scs10ygu@rclogin ~/Training]$ diff lorem.txt lorem.txt.bak
< lectus. There are two statements in this document in English. Donec velit
--> lectus. There is one statement in this document in English. Donec velit
Lines beginning with a < denotes file1, while lines beginning with a > denotes file2.
Like sed, the awk command is such a powerful tool which has so many options we can only scratch the surface
of its use in this tutorial. Awk is most commonly used as a data formatting, extraction and processing tool.
The first awk example shows how it can be used to extract data from a file. Here, using the –F option to set
the field separator as “,” we tell awk to print out only the first field ($1) of the sales.csv file. Using this method
we can print out the sales for each month, for example $3 for February etc.
[scs10ygu@rclogin ~/Training]$ cat sales.csv | awk -F"," '{print $1}'
Sales Area
Displaying specific data is one example, but awk can also be used to process data. Rather than just printing
out the specified column, this example sums the data in the fifth column for each row in the csv file, and prints
the total.
[scs10ygu@rclogin ~/Training]$ tail -n6 sales.csv | awk -F"," '{ SUMAPR += $5} END {
print "April: " SUMAPR }'
April: 14
Exercise data manipulation:
Find the quote from Linus Torvalds in lorem.txt and redirect this to a new file. Hint: Use –i for grep to
ignore the case of the search.
Sort the sales figures from sales.csv based on the month of May. Hint: sort has options to allow
different keys (columns) to be the basis of the sort. By default sort uses a space as a field separator,
use man to see the options for sort.
Processes and jobs
A process is an executing program identified by a unique PID (process identifier). To see information about
your processes, with their associated PID and status, type ps
[scs10ygu@rclogin ~/Training]$ ps
21800 pts/6
00:00:00 tcsh
21857 pts/6
00:00:00 ps
A process may be in the foreground, in the background, or be suspended. In general the shell does not return
the Linux prompt until the current process has finished executing.
Some processes take a long time to run and hold up the terminal. Backgrounding a long process has the effect
that the Linux prompt is returned immediately, and other tasks can be carried out while the original process
continues executing.
The command top will display an updating list of every process that is running on the computer you are
connected to. The top banner shows how the overall processor usage of the computer (load average: over 1
minute, 5 minutes and 15 minutes) along with the total memory usage (Mem). The list then shows information
like the process ID (PID), the user, processor (%CPU) and memory (%MEM) usage for each process. Press q to
quit out from top.
top - 14:14:34 up 852 days, 4:17, 8 users, load average: 0.04, 0.05, 0.00
Tasks: 616 total,
1 running, 615 sleeping,
0 stopped,
0 zombie
Cpu(s): 0.1%us, 0.0%sy, 0.0%ni, 99.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 132072040k total, 80332856k used, 51739184k free, 1200456k buffers
Swap: 16779884k total,
0k used, 16779884k free, 76518156k cached
0 130m 96m 3616 S 2.0 0.1 435:41.33 vasd
0 22452 1884 1112 R 0.7 0.0
0:00.07 top
0 10348 632 540 S 0.0 0.0
0:25.13 init
0 S 0.0 0.0
3:49.41 migration/0
0 S 0.0 0.0
0:00.43 ksoftirqd/0
0 S 0.0 0.0
0:00.00 watchdog/0
0 S 0.0 0.0
3:43.56 migration/1
0 S 0.0 0.0
0:00.91 ksoftirqd/1
0 S 0.0 0.0
0:00.00 watchdog/1
0 S 0.0 0.0
3:42.99 migration/2
0 S 0.0 0.0
0:00.40 ksoftirqd/2
0 S 0.0 0.0
0:00.00 watchdog/2
0 S 0.0 0.0
3:48.34 migration/3
0 S 0.0 0.0
0:00.40 ksoftirqd/3
0 S 0.0 0.0
0:00.00 watchdog/3
0 S 0.0 0.0
1:26.32 migration/4
To background a process, type an & at the end of the command line. For example, the command sleep waits a
given number of seconds before continuing. Running the command sleep 10 will wait 10 seconds before
returning to the command prompt. Until the command prompt is returned, you can do nothing except wait.
The & runs the job in the background and returns the prompt straight away, allowing you do run other
programs while waiting for that one to finish. The first line in the example below is typed in by the user; the
next line, indicating job number and PID, is returned by the machine.
[scs10ygu@rclogin ~/Training]$ sleep 1000 &
[1] 21884
The user is notified of a job number (numbered from 1) enclosed in square brackets, together with a PID and
is notified when a background process is finished. Putting tasks in the Background is useful for jobs which will
take a long time to complete. Note however that you should avoid backgrounding programs that require user
interaction e.g. vi. At the prompt, type sleep 999 you can then suspend the process running in the
foreground by typing ^Z, i.e. hold down the [Ctrl] key and type [z]. Then to put it in the background, type
When a process is running, backgrounded or suspended, it will be added to the list of running jobs. Start
another sleep process and again suspend it, but this time do not run it in the background and examine your
process list by typing jobs
[scs10ygu@rclogin ~/Training]$ sleep
[scs10ygu@rclogin ~/Training]$ jobs
[2] - Running
[3] + Suspended
sleep 1000
sleep 999
sleep 998
To restart (foreground) a suspended processes, type fg %jobnumber for example, to restart sleep 998, type
fg %3. Typing fg with no job number foregrounds the last suspended process (indicated with the + in the
jobs display).
Killing a process
It is sometimes necessary to kill a process (for example, when an executing program is in an infinite loop). To
kill a job running in the foreground, type ^C (control c). For example, run sleep 100 followed by ^C which
will kill the sleep process. To kill a suspended or background process, type kill %jobnumber for example.
The jobs command allows you to check whether this has worked.
[4] 29962
[1] - Running
[2] + Suspended
[1] - Running
[2] + Suspended
~/Training]$ sleep 100 &
~/Training]$ jobs
~/Training]$ kill %4
~/Training]$ jobs
If you have a unique job (for example, a single running sleep) you can use the pkill command with the
command name, for example:
[scs10ygu@rclogin ~/Training]$ sleep
[1] 30188
[scs10ygu@rclogin ~/Training]$ jobs
[1] + Running
[scs10ygu@rclogin ~/Training]$ pkill
[1] + Terminated
100 &
sleep 100
sleep 100
!Note: It is not possible to kill off other users' processes!
File permissions
Using the ls command seen earlier with the –l flag for long listing, we can see additional information about
a file or directory, including who has permission to see the file:
[scs10ygu@rclogin ~/Training]$ ls -l lorem.txt
-rw-r--r-- 1 scs10ygu itcs 73164 Nov 10 20:11 lorem.txt
For lorem.txt the file has the following extra information:
-rw-r--r-- 1 scs10ygu itcs 73164 Nov 10 20:11 lorem.txt
-rw-r--r—permissions on the file (explained below)
scs10ygu owner of the file (or directory)
itcs group owning the file (or directory)
73164 size of the file (in bytes; can be changed with the –h flag)
Nov 10 20:11 date and time of creation
lorem.txt name of file (or directory)
In the left-hand column is a 10 symbol string consisting of the symbols d, r, w, x, -, and, occasionally, s or S. If
d is present, it will be at the left hand end of the string, and indicates a directory: otherwise – it will be the
starting symbol of the string.
The 9 remaining symbols indicate the permissions, or access rights, and are taken as three groups of 3.
The left group of 3 gives the file permissions for the user that owns the file (or directory) (cc in the
above example)
The middle group gives the permissions for the group of people to whom the file (or directory) belongs
(itcs in the above example)
The rightmost group gives the permissions for all others
The symbols r, w, etc., have slightly different meanings depending on whether they refer to a simple file or to
a directory.
Access rights on files.
r (or -), indicates read permission (or otherwise), that is, the presence or absence of permission to read and
copy the file
w (or -), indicates write permission (or otherwise), that is, the permission (or otherwise) to change a file
x (or -), indicates execution permission (or otherwise), that is, the permission to execute a file, where
Access rights on directories.
r allows users to list files in the directory;
w means that users may delete files from the directory or move files into it;
x means the right to access files in the directory. This implies that you may read files in the directory provided
you have read permission on the individual files.
So, in order to read a file, you must have execute permission on the directory containing that file, and hence
on any directory containing that directory as a subdirectory, and so on, up the tree.
Examples of file permissions on files could be:
a file that everyone can read, write and execute (and delete).
a file that only the owner can read and write - no-one else can read
or write and no-one has execution rights (e.g. your mailbox file).
Changing permissions
Only the owner of a file can use chmod to change the permissions of a file. The options of chmod are as follows:
Write (and delete)
Execute (and access directory)
Add permission
Take away permission
For example, to remove read permissions on the file lorem.txt for the group and others, type:
[scs10ygu@rclogin ~/Training]$
-rw-r--r-- 1 cc itcs 73165 Nov
[scs10ygu@rclogin ~/Training]$
[scs10ygu@rclogin ~/Training]$
-rw------- 1 cc itcs 73165 Nov
ls -l lorem.txt
10 20:11 lorem.txt
chmod go-r lorem.txt
ls -l lorem.txt
10 20:11 lorem.txt
This means that only the only, cc, can now read this file. Permissions can also be set using octal notation,
where each set of three permissions (user, group, other) is represented by a number.
Octal value
Octal value
For example, chmod 755 filename results in filename having read, write and execute permissions for user;
and read and execute for both group and other. The octal chmod commands for our previous example are:
chmod 777 filename
chmod 600 filename
a file that everyone can read, write and
execute (and delete).
a file that only the owner can read and write no-one else can read or write and no-one has
execution rights (e.g. your mailbox file).
Compiling Linux software
There are many public domain and commercial software packages installed on our systems, which are
available to all users. However, users are allowed to download and install small software packages in their
own home directory, software usually only useful to them personally. There are a number of steps needed to
install the software.
Locate and download the source code (which is usually compressed)
Unpack the source code
Compile the code
Install the resulting executable
Set paths to the installation directory
Steps 1 and 2 have already been covered earlier in this tutorial, with the use of wget, scp and tar. Of the above
steps, probably the most difficult is the compilation stage.
Compiling source code
All high-level language code must be converted into a form the computer understands. For example, C
language source code is converted into a lower-level language called assembly language. The assembly
language code made by the previous stage is then converted into object code, which are fragments of code
which the computer understands directly. The final stage in compiling a program involves linking the object
code to code libraries which contain certain built-in functions. This final stage produces an executable
program. To do all these steps by hand is complicated and beyond the capability of the ordinary user. A
number of utilities and tools have been developed for programmers and end-users to simplify these steps.
make and the Makefile
The make command allows programmers to manage large programs or groups of programs. It aids in
developing large programs by keeping track of which portions of the entire program have been changed,
compiling only those parts of the program which have changed since the last compile.
The make program gets its set of compile rules from a text file called Makefile which resides in the same
directory as the source files. It contains information on how to compile the software, e.g. the optimisation
level, whether to include debugging info in the executable. It also contains information on where to install the
finished compiled binaries (executables), manual pages, data files, dependent library files, configuration files,
etc. Some packages require you to edit the Makefile by hand to set the final installation directory and any
other parameters. However, many packages are now being distributed with the GNU configure utility.
As the number of UNIX variants increased, it became harder to write programs which could run on all variants.
Developers frequently did not have access to every system, and the characteristics of some systems changed
from version to version. The GNU configure and build system simplifies the building of programs distributed
as source code. All programs are built using a simple, standardised, two-step process. The program builder
need not install any special tools in order to build the program.
The configure shell script attempts to guess correct values for various system-dependent variables used
during compilation. It uses those values to create a Makefile in each directory of the package.
The simplest way to compile a package is:
cd to the directory containing the package's source code.
Type ./configure to configure the package for your system.
Type make to compile the package.
Optionally, type make check to run any self-tests that come with the package.
Type make install to install the programs and any data files and documentation.
Optionally, type make clean to remove the compilation files from the source code directory
The configure utility supports a wide variety of options. You can usually use the --help option to get a list
of interesting options for a particular configure script.
The only generic options you are likely to use are the --prefix and --exec-prefix options. These options
are used to specify the installation directories. The directory named by the --prefix option will hold
machine independent files such as documentation, data and configuration files. The directory named by the
--exec-prefix option, (which is normally a subdirectory of the --prefix directory), will hold machine
dependent files such as executable files.
Exercise: Example install
Download the file and check it is correct (the md5sum is
230d1cb0367f9f4ac345beda371bbb53) and uncompress the file and change directory into units-1.74
Run the configure utility setting the installation path to:
./configure --prefix=$HOME/units174
NOTE: The $HOME variable is an example of an environment variable. The value of $HOME is
the path to your home directory. Just type echo $HOME to show the contents of this variable.
We will learn more about environment variables in a later chapter
If configure has run correctly, it will have created a Makefile with all necessary options. You can view the
Makefile if you wish (use the less command), but do not edit the contents of this
Now you can go ahead and build the package by running make. After a minute or two (depending on the
speed of the computer), the executables will be created. You can check to see everything compiled
successfully by typing make check and if everything is okay, you can now install the package by running
make install this will install the files into the ~/units174 directory you created earlier
cd to where units is installed. List the contents of this directory and you will see a number of subdirectories.
The binary executables
GNU info formatted documentation
Man pages
Shared data files
To run the program, change to the bin directory and type ./units as an example, convert 6 feet to
metres. If you get the answer 1.8288, congratulations, it worked! To view what units it can convert
between, view the data file in the share directory (the list is quite comprehensive).
To read the full documentation, change into the info directory and type info
Linux shell variables
Variables are a way of passing information from the shell to programs when you run them. Programs look "in
the environment" for particular variables and if they are found will use the values stored. Some are set by the
system, others by you, yet others by the shell, or any program that loads another program.
Standard UNIX variables are split into two categories, environment variables and shell variables. In broad
terms, shell variables apply only to the current instance of the shell and are used to set short-term working
conditions; environment variables have a farther reaching significance, and those set at login are valid for the
duration of the session. By convention, environment variables have UPPER CASE and shell variables have lower
case names.
Environment variables
An example of an environment variable is the OSTYPE variable. The value of this is the current operating
system you are using. Type
[scs10ygu@rclogin ~]$ echo $OSTYPE
More examples of environment variables are
USER (your login name)
HOME (the path name of your home directory)
HOST (the name of the computer you are using)
ARCH (the architecture of the computers processor)
DISPLAY (the name of the computer screen to display X windows)
PRINTER (the default printer to send print jobs)
PATH (the directories the shell should search to find a command)
ENVIRONMENT variables are set using the setenv command, displayed using the printenv or env
commands, and unset using the unsetenv command. To show all values of these variables, type printenv
| less
Shell variables
An example of a shell variable is the history variable. The value of this is how many shell commands to save,
allow the user to scroll back through all the commands they have previously entered. Type
[scs10ygu@rclogin ~]$ echo $history
More examples of shell variables are
cwd (your current working directory)
home (the path name of your home directory)
path (the directories the shell should search to find a command)
prompt (the text string used to prompt for interactive commands shell your login shell)
SHELL variables are both set and displayed using the set command. They can be unset by using the unset
command. To show all values of these variables, type set | less
In general, environment and shell variables that have the same name (apart from the case) are distinct and
independent, except for possibly having the same initial values. There are, however, exceptions.
Each time the shell variables home, user and term are changed, the corresponding environment variables
HOME, USER and TERM receive the same values. However, altering the environment variables has no effect
on the corresponding shell variables.
PATH and path specify directories to search for commands and programs. Both variables always represent the
same directory list, and altering either automatically causes the other to be changed.
Using and setting variables
Each time you login to a UNIX host, the system looks in your home directory for initialisation files. Information
in these files is used to set up your working environment. The C and TC shells uses two files called .login and
.cshrc (note that both file names begin with a dot).
At login the C shell first reads .cshrc followed by .login
.login is to set conditions which will apply to the whole session and to perform actions that are relevant only
at login.
.cshrc is used to set conditions and perform actions specific to the shell and to each invocation of it.
The guidelines are to set ENVIRONMENT variables in the .login file and SHELL variables in the .cshrc file.
!!!Note: NEVER put commands that run graphical displays (e.g. a web browser) in your .cshrc or .login file!!!
Setting shell variables in the .cshrc file
For example, to change the number of shell commands saved in the history list, you need to set the shell
variable history. It is set to 1000 by default, but you can increase this if you wish by running set history =
2000 Check this has worked by typing echo $history
However, this has only set the variable for the lifetime of the current shell. If you open a new xterm window,
it will only have the default history value set. To PERMANENTLY set the value of history, you will need to add
the set command to the .cshrc file.
First open the .cshrc file in a text editor. Details of text editors can be found in the next section. An easy, userfriendly editor to use is nano: nano –w ~/.cshrc
Add the following line AFTER the list of other commands:
set history = 2000
Save the file and force the shell to reread its .cshrc file buy using the shell source command source .cshrc
Check this has worked by typing echo $history
Setting the path
When you type a command, your path (or PATH) variable defines in which directories the shell will look to find
the command you typed. If the system returns a message saying "command: Command not found", this
indicates that either the command doesn't exist at all on the system or it is simply not in your path.
For example, to run units, you either need to directly specify the units path (~/units174/bin/units), or you
need to have the directory ~/units174/bin in your path.
You can add it to the end of your existing path (the $path represents this) by issuing the command set path
= ($path ~/units174/bin)
Test that this worked by trying to run units in any directory other that where units is actually located.
[scs10ygu@rclogin ~]$ units
units: Command not found.
[scs10ygu@rclogin ~]$ set path = ($path ~/units174/bin)
[scs10ygu@rclogin ~]$ units
1948 units, 71 prefixes, 28 functions
You have:
To add this path PERMANENTLY, add the following line to your .cshrc AFTER the list of other commands set
path = ($path ~/units174/bin)
There are many editors available for Linux, however the most common are briefly outlined below. Nano is
arguably the most simple for the first time user, whilst Vi and emacs are more powerful, while nedit is good
for those used to a windows environment. Which to use is down to personal preference, below is a very brief
guide to each, with some of the most common commands highlighted.
nano (formerly pico) is probably the simplest standard editor and appears at first glance as most Windows
text editors do - called with nano filename, if filename doesn't exist a blank page opens ready for
composition, if filename does exist then the file is opened for editing. Unlike many console apps, pico can't be
put to the background with CTRL Z. Start with nano -w filename to turn word wrap off
Cut line
Paste line
Find again
Find line number
Next page
Previous page
CTRL + o
CTRL + x (then confirm
CTRL + k (within nano only)
CTRL + u (within nano only)
CTRL + w (then enter search string
CTRL + w
CTRL + w CTRL + t
CTRL + v
CTRL + y
CTRL + g
vi (vim) is a more powerful but more complicated tool, allowing for elegant mass editing of text. Vi can be
started either with the traditional vi filename or when lessing a file, by pressing v (note exiting vi here will
return to the less view). Vi has many commands allowing for all sorts of editing shortcuts, the most common
presented below. Unlike Nano and Windows editors, a new vi session does not immediately allow you to write,
instead you must invoke the insertion mode (i or a etc). Pressing ESC then exits the editing mode and returns
you to reading mode, enabling you to save etc. Part of benefit of vi is the ability to incorporate sed commands
into the editing, which is very useful, lots of instructions available through search engines.
Save and exit
Insert (before cursor)
Append text (after cursor)
Open new line below
Delete line
Copy line
Delete word
Change word
Copy line
Find again
Next page
Previous page
i (ESC to exit)
a (ESC to exit)
o (ESC to exit)
CTRL + f
CTRL + b
Similar to vi, emacs is a more powerful editor. It allows users to create macros and fine grained customisations.
The emacs short cut keys are the ones used for the BASH shell. There is a plethora of documentation and good
books available on emacs, with support for the many programming languages, LaTeX and shell scripting. Below
is a screen shot of emacs.
To edit a file in emacs, type emacs -nw filename.tex - the table below lists the most common emacs
functions. Save CTRL x + CTRL s
Load filename
Cut line
Paste line
Find forward
Find reverse
Beginning of document
End of document
Page up
Page down
Upper case word
Lower case word
CTRL x + CTRL f filename
What to do next
Remote access:
You can continue using the general purpose UEA Linux login server. It is available for access
from inside and outside the University, you will just need an SSH client such as PuTTY.
High Performance Computing:
If you have a particular computational requirement in your work, then you can request an account on the UEA
HPC cluster by submitting the application form available at:
More information about the UEA HPC can be found at
On a UEA PC:
The UEA Linux desktop is Ubuntu 14.04 LTS and provides a secure graphical desktop that is integrated with
UEA central IT systems.
More information about the UEA Linux desktop can be found at If you would like to have Linux installed on your UEA desktop or laptop, please
On your own PC:
There are various options for trying Linux on your own computer without replacing Windows. Firstly, there
are numerous Linux Live CD and USB images which allow you to boot from removable media into a full featured
Linux environment.
The Ubuntu Live image is available at:
An installer for Windows is also available which allows you to install Ubuntu like an application in Windows,
providing you with a computer that can boot into both Windows and Linux. This is available at
!!Note: Please read and follow the instructions for both Live CD/USB and the
Windows installer very carefully to avoid any data loss!!
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF