# UNIX introduction

Document Sample

					                                     T
AF
An Introduction to

U NIX
as used at Nada & KTH CSC
DR

Stockholm 2010

KTH   School of Computer Science and Communication
SU   Numerical Analysis and Computer Science
NADA
T
AF
DR

2.0nd edition, August 12, 2010
Author: Per Sedholm
Based on an earlier Swedish document by: Mårten Svantesson, David,
Vuorio, Lena Nylén, Richard Spångberg, Jörgen Björkner, Anna Herting,
Mattias Frånberg
The front drawing is by Jesper Oppelstrup.
Opinions and comments are welcomed at system@csc.kth.se
Contents
Contents                                                                                                    i

Introduction                                                                     iv

T
History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv
. . . and we will all behave appropriately! . . . . . . . . . . . . . . . . v
How to read this document . . . . . . . . . . . . . . . . . . . . . . . v

1 Logging in                                                                                               1
1.1 File storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                             1
1.2 Computer support . . . . . . . . . . . . . . . . . . . . . . . . .                                   2

2 Graphical User Interface (GUI)                                                                           3

AF
2.1 Mouse and keyboard . . . . . . . . . . .         .   .   .   .   .   .   .   .   .   .   .   .   .   3
2.1.1 Mouse—using all three buttons              .   .   .   .   .   .   .   .   .   .   .   .   .   3
2.1.2 Keyboards . . . . . . . . . . . . .        .   .   .   .   .   .   .   .   .   .   .   .   .   3
2.2 Character encoding (UTF-8 or Latin-1) .          .   .   .   .   .   .   .   .   .   .   .   .   .   6

3 Ubuntu                                                                                                    7
3.1 Logging in . . . . . . . . . . . . . . . . . . . . . . . .                   .   .   .   .   .   .    7
3.1.1 Failsafe login (in case of problems) . . . . . .                       .   .   .   .   .   .    7
3.2 Gnome Desktop . . . . . . . . . . . . . . . . . . . . .                      .   .   .   .   .   .    7
3.2.1 Running applications (programs) . . . . . . .                          .   .   .   .   .   .    8
3.3 Internet and communication . . . . . . . . . . . . .                         .   .   .   .   .   .    9
3.4 Ofﬁce applications (word processing, spreadsheets)                           .   .   .   .   .   .   10
3.5 Graphics . . . . . . . . . . . . . . . . . . . . . . . . .                   .   .   .   .   .   .   10
3.6 Text editors . . . . . . . . . . . . . . . . . . . . . . .                   .   .   .   .   .   .   11
3.7 Removable media (USB sticks, etc.) . . . . . . . . .                         .   .   .   .   .   .   12
3.7.1 Printing . . . . . . . . . . . . . . . . . . . . .                     .   .   .   .   .   .   12
3.8 LTEX . . . . . . . . . . . . . . . . . . . . . . . . . . . .
A                                                                           .   .   .   .   .   .   13
DR
4 Mac OS X                                                                                                 15
4.1 Logging in . . . . . . . . . . . . . . . . . . .         .   .   .   .   .   .   .   .   .   .   .   15
4.2 Finder . . . . . . . . . . . . . . . . . . . . . .       .   .   .   .   .   .   .   .   .   .   .   15
4.2.1 Removable media (USB sticks, etc.)                 .   .   .   .   .   .   .   .   .   .   .   16
4.2.2 Keychain . . . . . . . . . . . . . . . .           .   .   .   .   .   .   .   .   .   .   .   16
4.3 Internet . . . . . . . . . . . . . . . . . . . . .       .   .   .   .   .   .   .   .   .   .   .   16
4.4 Ofﬁce applications . . . . . . . . . . . . . .           .   .   .   .   .   .   .   .   .   .   .   17
4.4.1 iWork . . . . . . . . . . . . . . . . . .          .   .   .   .   .   .   .   .   .   .   .   17
4.4.2 MS Ofﬁce 2008 . . . . . . . . . . . .              .   .   .   .   .   .   .   .   .   .   .   17
4.4.3 Plain text; LTEX . . . . . . . . . . . .
A                                   .   .   .   .   .   .   .   .   .   .   .   18
4.5 Graphics . . . . . . . . . . . . . . . . . . . .         .   .   .   .   .   .   .   .   .   .   .   18
4.5.1 The Adobe suite: CS5 . . . . . . . .               .   .   .   .   .   .   .   .   .   .   .   18
4.5.2 Other applications (selected) . . . .              .   .   .   .   .   .   .   .   .   .   .   18
4.5.3 Printing . . . . . . . . . . . . . . . .           .   .   .   .   .   .   .   .   .   .   .   19

5 Solaris                                                                                                  20
5.1 Logging in . . . . . . . . . . . . . . . . . . .         .   .   .   .   .   .   .   .   .   .   .   20
5.1.1 Failsafe login (in case of problems) .            .   .   .   .   .   .   .   .   .   .   .   20
5.1.2 Thin clients (SunRay terminals) . .               .   .   .   .   .   .   .   .   .   .   .   20
5.1.3 Java Desktop System (JDS) . . . . .               .   .   .   .   .   .   .   .   .   .   .   21
5.1.4 Removable media (USB sticks, etc.)                .   .   .   .   .   .   .   .   .   .   .   22

6 The   U NIX command-line                                                                                 23
6.1   Basics: shell, prompt, path . . . . . . . . . . . . . . . . .                          .   .   .   24
6.2   Change user password (kpasswd) . . . . . . . . . . . . . .                             .   .   .   24
6.3   Commands . . . . . . . . . . . . . . . . . . . . . . . . . . .                         .   .   .   24
6.3.1 Navigating in the ﬁle system (cd och pwd) . . . . .                              .   .   .   25
6.3.2 List ﬁles (ls) . . . . . . . . . . . . . . . . . . . . . .                       .   .   .   26
6.3.3 Create and remove directories (mkdir and rmdir)                                  .   .   .   26

i
6.3.4 Move and copy ﬁles (mv and cp) . . . .                                .   .   .   .   .   .   .   .   .   27
6.3.5 Remove ﬁles (rm) . . . . . . . . . . . . .                            .   .   .   .   .   .   .   .   .   27
6.3.6 Show text ﬁles (cat, more, less) . . . .                              .   .   .   .   .   .   .   .   .   27
6.3.7 Printing . . . . . . . . . . . . . . . . . .                          .   .   .   .   .   .   .   .   .   27

T
6.3.8 Symbolic links (ln -s) . . . . . . . . . .                            .   .   .   .   .   .   .   .   .   28
6.3.9 Access rights (fs, chmod) . . . . . . . .                             .   .   .   .   .   .   .   .   .   29
6.3.10 Display text (echo) . . . . . . . . . . . .                          .   .   .   .   .   .   .   .   .   31
6.3.11 Programs and processes (kill, fg, bg)                                .   .   .   .   .   .   .   .   .   31
6.4   Concepts . . . . . . . . . . . . . . . . . . . . . .                        .   .   .   .   .   .   .   .   .   32
6.4.1 Command, argument, option . . . . . .                                 .   .   .   .   .   .   .   .   .   32
6.4.2 The ﬁle tree . . . . . . . . . . . . . . . .                          .   .   .   .   .   .   .   .   .   33

AF
7 Details                                                                                                                35
7.1 More about the command-line interface . . . . . . .                                        .   .   .   .   .   .   35
7.1.1 Command history . . . . . . . . . . . . . . .                                       .   .   .   .   .   .   35
7.1.2 Wildcards . . . . . . . . . . . . . . . . . . . .                                   .   .   .   .   .   .   35
7.1.3 Script . . . . . . . . . . . . . . . . . . . . . . .                                .   .   .   .   .   .   35
7.1.4 Tab completion . . . . . . . . . . . . . . . . .                                    .   .   .   .   .   .   36
7.1.5 Redirection . . . . . . . . . . . . . . . . . . .                                   .   .   .   .   .   .   36
7.1.6 Alias and functions . . . . . . . . . . . . . . .                                   .   .   .   .   .   .   38
7.1.7 Exporting environment variables . . . . . . .                                       .   .   .   .   .   .   38
7.1.8 Modules . . . . . . . . . . . . . . . . . . . . .                                   .   .   .   .   .   .   38
7.2 AFS och Kerberos . . . . . . . . . . . . . . . . . . . .                                   .   .   .   .   .   .   39
7.2.1 Tickets . . . . . . . . . . . . . . . . . . . . . .                                 .   .   .   .   .   .   39
7.2.2 Quota . . . . . . . . . . . . . . . . . . . . . .                                   .   .   .   .   .   .   40
7.3 Special access rights . . . . . . . . . . . . . . . . . .                                  .   .   .   .   .   .   40
7.3.1 Access groups . . . . . . . . . . . . . . . . . .                                   .   .   .   .   .   .   40
7.3.2 Backups—OldFiles . . . . . . . . . . . . . . .                                      .   .   .   .   .   .   40
DR
7.3.3 Shared directories . . . . . . . . . . . . . . .                                    .   .   .   .   .   .   41
7.3.4 Different access rights in the same directory                                       .   .   .   .   .   .   42
7.4 Homepage (public_html) . . . . . . . . . . . . . . .                                       .   .   .   .   .   .   42
7.5 Remote access (ssh) . . . . . . . . . . . . . . . . . .                                    .   .   .   .   .   .   43
7.5.1 Terminal access (SSH) . . . . . . . . . . . . .                                     .   .   .   .   .   .   43
7.5.2 File transfer (SFTP, SCP) . . . . . . . . . . .                                     .   .   .   .   .   .   44
7.5.3 X11 forwarding . . . . . . . . . . . . . . . . .                                    .   .   .   .   .   .   44
7.5.4 Heavy processing . . . . . . . . . . . . . . . .                                    .   .   .   .   .   .   45
7.5.5 Kerberos remote access . . . . . . . . . . . .                                      .   .   .   .   .   .   45

8 Emacs                                                                                                                  47
8.1 Text editing, cut-and-paste        .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   48
8.2 Searching . . . . . . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   48
8.3 Handling multiple ﬁles . . .       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   49
8.4 Modes . . . . . . . . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   49
8.5 Settings . . . . . . . . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   49
8.6 Help . . . . . . . . . . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   50
8.7 Alternate applications . . .       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   50

9 Programming                                                                                                            51
9.1 Java . . . . . . . . . . . . . . . . . . . . . . . . . . .                             . . . . . .             .   51
9.1.1 Integrated Development Environment, IDE                                         (Eclipse)               .   52
9.2 Python . . . . . . . . . . . . . . . . . . . . . . . . .                               . . . . . .             .   52
9.2.1 IDE (Idle) . . . . . . . . . . . . . . . . . . . .                              . . . . . .             .   52
9.3 M ATLAB . . . . . . . . . . . . . . . . . . . . . . . . .                              . . . . . .             .   52
9.3.1 Octave . . . . . . . . . . . . . . . . . . . . .                                . . . . . .             .   53

ii
10 Documentation and help                                                                                                             54
10.1 Man pages (man, info) . . . . . . . . . . . . . . . . . .                                                 .   .   .   .   .   54
10.2 Online support . . . . . . . . . . . . . . . . . . . . . .                                                .   .   .   .   .   55
10.3 Personal assistance, tutors . . . . . . . . . . . . . . .                                                 .   .   .   .   .   55
10.3.1 Course assistants . . . . . . . . . . . . . . . .                                                  .   .   .   .   .   55

T
10.3.2 Sima Manager . . . . . . . . . . . . . . . . . . .                                                 .   .   .   .   .   55
10.3.3 Allmänhandledning, the general assistant . .                                                       .   .   .   .   .   56
10.3.4 Systemgruppen, the KTH CSC Systems Group                                                           .   .   .   .   .   56
10.3.5 Other computer support . . . . . . . . . . . . .                                                   .   .   .   .   .   56
10.4 Speciﬁc problems—FAQ . . . . . . . . . . . . . . . . .                                                    .   .   .   .   .   56
10.5 If you have an old CSC account . . . . . . . . . . . . .                                                  .   .   .   .   .   58
10.5.1 Strange username . . . . . . . . . . . . . . . .                                                   .   .   .   .   .   58
10.5.2 “Wrong” shell (tcsh or bash) . . . . . . . . . . .                                                 .   .   .   .   .   58
10.5.3 Old settings . . . . . . . . . . . . . . . . . . . .                                               .   .   .   .   .   58

AF
10.5.4 Restore default settings . . . . . . . . . . . . .                                                 .   .   .   .   .   58

11 Course administration                                                                                                              59
11.1 My Pages . . . . . .      .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   59
11.2 rapp . . . . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   59
11.3 course . . . . . . .      .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   59
11.4 res . . . . . . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   59

A Some terms                                                                                                                          62

B Common characters                                                                                                                   63

C Selected applications                                                                                                               65

Index                                                                                                                              67

D Quick guide to U NIX commands                                                                                                       71

E Quick guide to Emacs                                                                                                                72
DR

iii
Introduction

Introduction
This document aims to give some basic knowledge of the computer envi-
ronment you will be using at KTH CSC, the School of Computer Science
and Communication. KTH CSC uses many different operating systems:1

T
• Apple computers running Mac OS X

• PC computers running Microsoft Windows

• PCs running Ubuntu Linux

• Sun workstations running Solaris2

Differences in the computer hardware aside, the different OSs means

AF
you cannot always use the same software in the different environments.
Most of CSC’s “standard software”, e.g. M ATLAB,3 are however available in
all environments.
Most people today have some familiarity with with MS Windows or Mac
OS X, but possibly not with the U NIX and Linux systems used in the com-
puter rooms. The emphasis of this document is therefore to highlight the
differences of U NIX and Linux compared to MS Windows or OS X, rather
than to assume4 that explanations are needed for every particular of how
to use a computer. Except where noted, most software works in a similar
fashion on both U NIX and Linux systems.

History
U NIX is a family of operating systems that can trace their roots to Unics, an
operating system used at AT&T’s Bell Labs in 1969. In order to ofﬁcially be
certiﬁed as a U NIX system, and use the U NIX trademark, an OS must have
been developed from (or share the characteristics of) either V7 (Version 7
of Berkeley U NIX, a.k.a. the *BSD branch) or System V (Solaris, HP-UX,
DR
et al).
In practice, most people referring to “a U NIX system” mean “a U NIX-like
system”. In other words, that the system behaves like and provides the
tools one can expect of a U NIX system. This is sometimes referred to as
* NIX, in order to avoid problems with the trademark U NIX. Linux is one
such OS (though most versions are not formally certiﬁed as U NIX), as are
the various BSD systems and Mac OS X.

Apart from the kernel of the operating system, you also need a toolchain,
a set of programs and system libraries used to create and remove ﬁles
and directories, show a Graphical User Interface (GUI), to compile other
programs, and so on. A graphical ﬁle manager 5 is one such program. An
OS usually comprises a kernel, a toolchain, and a set of other applications
(word processors, web browsers, etc.). A Linux distribution is based on the
Linux kernel, and (usually) the GNU toolchain.
Ubuntu is a Linux distribution created by Canonical Ltd., a South
African-owned company. It is largely based on an earlier distribution, De-
bian. The name “Ubuntu” comes from Zulu and other Bantu languages.
1 An operating system, or “OS”, is the computer program that starts when you turn on

the computer, and which starts other programs and applications. It handles the hardware,
and the communication between programs, as well as network communication with other
systems.
2 Solaris is a registered trademark of Sun Oracle
3 M ATLAB is a registered trademark of The Mathworks, Inc.
4 ass·ume (v.)

1. to take for granted; presume
2. to make an ass out of u and me

5 Explorer   in MS Windows, Finder in Mac OS X

iv
Introduction

• U NIX http://en.wikipedia.org/wiki/UNIX

• Linux http://en.wikipedia.org/wiki/Linux

• GNU-projektet http://en.wikipedia.org/wiki/GNU_project

T
. . . and we will all behave appropriately!
All computer users at KTH CSC have signed the KTH rules of conduct,
which states i.a.

Computing facilities, networks and accounts are the property of KTH,
and are run by KTH to be used in the activities and operations of KTH.
Other activities, such as non educational development, are only per-

AF
missible when
• regular use is not disturbed
• the activities do not violate these rules
• the activities do not violate KTH’s general instructions or [. . . ] any
applicable laws.

But it’s easy to forget, and one can sometimes be careless. Let us
therefore repeat some points.

• A password is private and should be kept secret. You can never lend
your password to someone.

• Commercial use of computer resources is prohibited.

• Storing illegal or pornographical material is not allowed.

• Copyright-protected material cannot be distributed.

• Offensive pictures shall neither be shown on screen nor printed.
DR
In addition, rules for the CSC work environment are posted in each
computer room.
Personal web pages must contain a button with a section sign (para-
graph mark, “§”) with a link to the standard disclaimer at the KTH website
http://www.kth.se/gemensamt/disclaimer .
These rules must be strictly adhered to. Further, it stricly prohibits po-
litical and religious propaganda and advertising for external organizations.
You are not allowed to publish links to, or otherwise engage in conduct or
activity connected to associations that may cause embarrassment to KTH,
either in Sweden or abroad.
Bookings for the computer rooms are available from TimeEdit
http://lokal2.timeedit.se/kth/ (the KTH schedule generator).6 You are
allowed to use the computers outside scheduled hours, but must give
precedence to those courses that have scheduled lab exercises. If someone
from a scheduled class requests your place, you must promptly save your
work and log out.

How to read this document
If you have never used a U NIX system, the best way to learn how is not
to read about it. Rather, log in to one of the machines, and try it out.
Start a web browser. Check out the ﬁle manager. See what settings are
available in the desktop environment—why not change the background
image?7 After that, you can look at the table of contents, to see what you
should read.
6 Go to “Jag vill leta bland lokalerna. . . ”, select “Datum” (the date, YYYY - MM - DD ); Region:

“KTH-campus”; Hus: “Huvudbyggnaden”; Lokaltyp: “Övriglokal”.
7 Right click on the desktop, Change Desktop Background

v
Introduction

That said, CSC students should also aquire a basic understanding of
how computer systems work. Although a modern U NIX environment can
be navigated strictly using the graphical tools (click icons in a graphical in-
terface to start applications, drag-and-drop ﬁles to move or remove them),
you should also learn how ﬁle systems are organized, how a command line

T
interface (CLI) works, and how to log in remotely to access systems over
the Internet. You should become comfortable with the most common op-
erating systems, so that you are tolerably familiar even with those you do
not normally use. Remember that even if you will not personally program
or adminster computer systems, you will most likely work with those who
do.
This document uses the following typographical conventions:
monospaced

AF
Text used in computer interaction, i.e. commands you write for the
computer, and the text written by the computer. Where spacing is
of particular importance, the text is written like this. Text
that should be replaced with something else, such as a username,
is shown like this. Non-relevant text is replaced by an ellipsis,
“[...]”.
Optional text, such as command-line arguments that can be omit-
ted, is surrounded by [brackets].
emphasis
Things of particular importance, such as terms and concepts, appli-
cation names, etc. Also, Swedish translations, where needed.
sans serif
Menus, window names, keyboard keys, buttons, etc.

3.1.1   References
Are shown like this , with a margin note to show which section
adresses the subject.

8    Shortcuts
DR
Usually written as Ctrl-X, Cmd-X, etc. In some contexts (Emacs            )
also C-x.

vi
Logging in

1     Logging in
KTH CSC’s computer rooms are located on the 4th and 5th ﬂoor of the main
building. Note that not all students are given access to all rooms.
The Windows machines use the same login.1 However, the Windows

T
proﬁle must be activated separately, which is only done for students whose
courses require access to these systems. This document does not describe
the use of Windows system, except insofar as they relate to the U NIX sys-
tems (e.g. how to transfer ﬁles2 ).

Brun
Grön
Gul
Orange
Röd
Blå
4th ﬂoor
20×Ubuntu
8×Ubuntu
20×Ubuntu
21×Ubuntu
21×Solaris
AF
E wing (west side)

(not for students)
Turkos
Violett
Magenta
Vit
Karmosin
Grå
5th ﬂoor
8×Mac OS X
16×Mac OS X
14×Win
7×Win
14×Ubuntu
13×Ubuntu
Mat
D wing (east side)

Konst
Musik
Sport
Spel
5th ﬂoor
10×Win
12×Mac OS X
9×Mac OS X
13×Ubuntu
24×Ubuntu

Translated, the names are (in order): Brown, Green, Yellow, Orange, Red, Blue, Turquise,
Violet, Magenta, White, Crimson, Grey (Gray), Food, Art, Music, Sport, Games
DR
All CSC computers are multi-user systems. In order to use them, you
must authenticate yourself, i.e. demonstrate that you have the proper
credentials to identify you as a particular user. On a workstation, this is
done when you give your password to log in.
Login screens can look slightly different. In some cases you type the
username, and then press «tab» (the key with , above Caps Lock) or «en-
ter» before typing your password. In others, there are two text ﬁelds, one
for the username and another for the password. The password is never
shown when you type it. Sometimes a symbol is shown to represent each
character, in other cases nothing is shown—the text ﬁeld is completely
empty.

Remember to log out when you leave
the computer!
If you leave the computer temporarily, you should lock the screen so
that no one else can use the computer in your name. You may not lock
the screen for more than 10 minutes.
If you are having trouble logging in, see the various user environments:                                                  3.1
Gnome (Ubuntu) or Mac OS X (Finder) .
4.1
1.1     File storage
The most common applications are stored locally, on the hard disk of the
computer you log in to. But your home directory is stored on a ﬁle system
1 This will be replaced with the centralized KTH login when the computers are upgraded to

Windows 7. (Autumn of 2010, tentatively.)
2 Remote access      7.5

1
Logging in

called AFS. Files in AFS are stored on ﬁle servers, and are backed up daily
(and weekly, monthly, etc.) to minimize the risk of losing data.
6.3.9      All home directories have a quota, typically 200 MB. You can see how
much you are using, the access rights, etc, with commands such as fs
lq and fs la.

T
Security is largely based on a protocol named Kerberos. You rarely need
to concern yourself with the details of this, but in case of trouble it may
help to know about the commands kauth and klist. (Even if you do not
use them, they may give information that is required when you ask for
help.)

1.2   Computer support
10

AF
The section on documentation provide information about system docu-
10.3    mentation, and online support, as well as KTH speciﬁc information about
whom to ask for help .
Problems with the computers should be reported to system@csc.kth.se.
DR

2
Graphical User Interface (GUI)

2      Graphical User Interface (GUI)
Today, GUIs are used in everything from mobile phones to ATMs. For per-
sonal computers, most GUIs contain more or less the same utilities. Ap-
plications are shown in one or several windows, which have a title bar with

T
buttons to maximize, minimize or close the window (and/or application).
You activate a window by clicking in it (or on the frame), and the active
window (application) is the one that has focus, that is, which accepts the
text typed on the keyboard, mouse motions, etc.
A desktop environment is the program that determines how this GUI
looks—the color of the window frames, where the minimize/maximize but-
tons are placed, icons, panels, tool ﬁelds to start applications, and so on.
The desktop environment is usually tightly afﬁliated with a ﬁle manager,

AF
and may also contain functionality found in this. For example, you can
usually drag-and-drop ﬁles directly from the desktop to an open applica-
tion in the same way that you move ﬁles between different directories in
the ﬁle manager.

2.1         Mouse and keyboard
What do you need to say about the mouse and the keyboard? Don’t they
work the same in U NIX as in any other operating system? Well, yes they
do. More or less. However, applications have traditionally used different
conventions, and you have a wider choice of keyboard settings.

2.1.1        Mouse—using all three buttons

U NIX workstations have traditionally used three button mice, even when
e.g. Windows only used two buttons. Hence, the third (actually middle)
button is used more than in other OSs.
DR
The primary (left) is used in the normal fashion, as is the secondary
(right) button, which usually gives a context menu. In addition to these,
the middle button (or scroll wheel1 ) can be used to paste text, after select-
ing it with the primary button. This makes it easy to copy a word such
as “ﬂoccinaucinihilipiliﬁcation” from a web page. You only need to double
click to select the word, and then middle click in your text document to
paste it.
Some web browsers override this, using middle click to open links in
new windows or tabs.

2.1.2        Keyboards

All modern keyboards have keys for typing uppercase letters (Shift) and
a control key (marked Ctrl), but others vary depending on the keyboard
and/or OS. Although the termes used so-called Super keys (Command,
Win and Meta; see below) varies, most keyboard shortcuts work similarly
in the different environments.
Most confusing, is probably to know what terms you should look for
in the documentation. When U NIX applications have used the Meta key,
the Alt (alternate) keys have often been substituted when using a PC key-
board (which used to lack Meta keys). Consequently, you press Alt-D to
remove an entire word after the cursor, but it is called Meta-D or M-d in
the documentation.
For details about the physical layout of various keyboards, see ﬁgure 1
on page 5. Brieﬂy:

1 You   can click the scroll whell, to use it as a third mouse button

3
Graphical User Interface (GUI)

Technically:       Command ≈ Windows ≈ Meta                (Super keys)
Alt = Option                            (Alternate)

Practically:       Command ≈ Control                       (Shortcuts)
Alt ≈ Meta                              (Usage)

T
It’s not as confusing as it may appear, but you may beneﬁt from learn-
ing a few terms.

Mac A Mac keyboard has a command key (Command, Cmd) and an al-
ternate key (Option, Opt or Alt). Shortcuts are usually Cmd-«key».

Windows ”Windows keyboards”2 has Control (Ctrl), Win, Alt, Alt Gr och

AF
Menu, the latter marked by a stylized context menu.3 But the Win and Alt
keys are reversed from the placement on the Mac keyboard. Shortcuts are
usually Ctrl-«key».

Solaris (Sun) U NIX has traditionally used more modiﬁer keys than other
OSs. There have been keyboards with up to seven different characters
available for each key.
In addition to the specialized shortcut keys to the left of the normal
alphanumerical keys, a Sun keyboard has Control, Alt, Meta, Compose and
Alt Graph keys. Shortcut usually use Control, but Meta is also common.
Java Desktop System (JDS), which is often used on the Solaris machines,
uses Alt.

Ubuntu (Linux) When used with a Windows keyboard, Linux uses the Alt
key as Meta. The Win key (called Super) is rarely used. But you can con-
ﬁgure keyboard shortcuts yourself, under System → Preferences → Keyboard
→ Layouts → Options.
DR
As usual, the Alt Gr key4 is used for some characters in Swedish or
other international keyboard layouts. For example, the key “2” gives

Modiﬁer:        (none)    shift    alt gr     shift + alt gr
2
Character:        2         "        @         (superscript)

Also, U NIX can (although not all keyboards have one) use an Compose
key. This is a so-called “dead” key, much as the acute and grave accent
used to write “á” and “à” on many European layouts, or the ∼ (tilde) key
on the US International layout (used for e.g. “ñ”).
The Compose key allow you to “combine” characters. For example,
Compose a e gives an “æ”, Compose , c a “ç” (c-cedilla).
A common modiﬁcation is to conﬁgure the right Win key as Compose.
2 Technically, 104 or 105 key IBM PC keyboard.
3 Context menu; a.k.a. popup menu, usually given by right clicking
4 A.k.a. Alt Graph, Mode Shift or ISO Level3 Shift

4
Mac

Windows, Linux
2.1 Mouse and keyboard

5
DR
Sun keyboard (Solaris)
AF
Figure 1: Keyboard comparison
T
Graphical User Interface (GUI)

2.2     Character encoding (UTF-8 or Latin-1)
How to encode text, that is, what binary sequences are used to represent
each letter, may vary between systems. Usually, an application such as
Emacs can recognize what has been used, and automatically convert text

T
if needed. But sometimes this doesn’t work, and you may need to conﬁgure
things manually.
CSC’s Solaris machines have for many years used a character encoding
called latin-1 (formally ISO-8859-1). If your terminal window is misconﬁg-
ured when you log in to a Solaris machine, this may cause all accented
characters (ÅÄÖ, éàïñ, etc.) to display strange characters.

AF
To convert the contents of a (plain text) ﬁle, iconv is available:

> iconv -f iso8859-1 -t utf-8 < original.txt > new.txt

The conversion is not perfect, though. If the text contains characters
that cannot be converted, you will get an error message:
DR
> iconv -f utf-8 -t iso8859-1 < cyrillic.txt
iconv: illegal input sequence at position 3

Unfortunately, many character encodings are still in use, even though
most programs now use either UTF-8 or latin-1. Some you may need to
recognize:

ASCII  Older American encoding, containing little more than the English
alphabet. Most of the more modern encodings are based upon ASCII
(and contain it as a subset).
ISO 8859-1 (w. space) Encoding for “latin” characters, i.e. those used in
(west) European languages.
ISO-8859-1, Latin-1 (w. dash) An extended version more suited for the
Internet, containing symbols for non-breaking space, degree symbol
(°), etc.
Windows-1252 Another extention, used in MS Windows. Contains for
example typographic quotes.

ISO-8859-15 Replacement for latin-1, to replace some rare characters (¼,
¾, etc.) with characters used in many European languages (C, œ,
etc.).

6
Ubuntu

3     Ubuntu

3.1     Logging in

T
AF
To log in, you use your CSC computer account. In other words, you
cannot use the central KTH.SE account     (used on e.g. My Pages). The
CSC account has (for new accounts) the same username as the KTH.SE
account, but not necessarily the same password.1
10.4
DR
3.1.1   Failsafe login (in case of problems)

If you cannot log in normally, you can try to log
in to a failsafe session. Click the blue arrow on
the bottom left, and choose Falsafe GNOME or Failsafe.
The ﬁrst gives you default settings for the window
manager (Gnome), but allows normal use of the sys-
tem. The second means that only a terminal window
is opened. This can be used if you need to clear
your Gnome settings—otherwise the active settings
are stored when you log out.
You can also use it if you can’t log in due to an
exceeded quota.2 You need to know (or look up) how
to use the command line.
10.5.4
To restore the default settings, see Restore default settings           .

3.2     Gnome Desktop

The window environment you face after logging in is called Gnome. Practi-
cally all aspects of the appearance may be altered, should you wish to, but
the default settings look approximately like this:

1 You may set the same password for both accounts, but they are not synchronized auto-

matically. If you change either password, the other one is not affected.
2 The quota     7.2.2 limits the amount of disk space that you can use.

7
Ubuntu

T
The major parts are:

AF
Application and system menus Here you will ﬁnd applications (Applica-
tions), directories (Places) and system settings (System).
Window panel Open applications are shown here.
Workspaces You can place application windows on different workspaces,
grouping them to give you quick access, or allow you to ﬂip back and
forth between a program and documentation, product speciﬁcations
etc.
Logout You log out by using the icon placed on far right.3

3.2.1    Running applications (programs)
Most applications can be found in submenus to Applications, for example
Firefox is under Applications → Internet → Firefox Web Browser.
DR
Since CSC’s computers are used for many different courses, a large
number of applications are installed. This can make it difﬁcult to navigate
the Application menu. If you want to remove some of the shortcuts for
applications you don’t use, or add some that you prefer, go to System →
Preferences → Main Menu.4

3 You can remove the panel containing the icon; then a logout menu will be shown under

System.
4 The menu Places is controlled by what bookmarks you have in the ﬁle manager, Nautilus.

8
3.3 Internet and communication

For quick access to applications, you can also add an icon on the desk-
top by right clicking an application and choosing Add this launcher to desk-
top. The launcher (icon) can then be moved to where you prefer.
You can also create your own Launchers, on the desktop or in the ap-
plication menu. Right click the desktop, choose Create Launcher. . . , and

T
enter:

Type: Application
Name: The name shown by the icon, cf. a ﬁle name
Command: The command to run
Comment: When placed in a menu, this is shown when you hover the
mouse marker over the icon

AF
You can also choose an appropriate icon. This launcher would open a
terminal with for remote access to a Solaris system, so a logo for the old
Sun corporation5 is used.

If you know the name of the executable for an application, you can run
it with the shortcut Alt+F2, and enter the name. E.g. baobab, which you
can also run from Application → Accessories → Disk Usage Analyzer.
7.5
DR
7.2.2
Note however that baobab does not at the moment understand AFS
quotas . It can’t show how much space is available on your home direc-
tory.

3.3       Internet and communication
Firefox is the most common web browser, but others are also installed, for
example Chromium.
For those who prefer not to use webmail (read their email in a browser),
Thunderbird is popular. There is also the more Outlook-inspired Evolu-
tion. In addition to email, it also has calendar and task list functions.
To select which application to use when you click on a link, go to System
→ Preferences → Preferred Applications.
5 Sun   is now a subsidary of Oracle

9
Ubuntu

T
3.4

AF
Ofﬁce applications (word processing, spreadsheets)

The ofﬁce suite OpenOfﬁce can read most word processing and spread-
sheet formats.
If you intend to move your document between different environments,
you may want to use the R TF format, or something similar.6
DR

3.5     Graphics

Many applications can be used for normal image editing. Images are by
default opened in Image Viewer (or “Eog”, Eye of Gnome), which can rotate
images, and save them in common ﬁle formats.
To edit an image, G IMP (GNU Image Manipulation Program) is probably
the most powerful application. It has, however, often been criticized for its
user interface.

6 Older versions of Microsoft Ofﬁce may otherwise have problems with the newer Open XML

(a.k.a. DOCX) format used by default in the latest versions of MS Ofﬁce. (OpenOfﬁce can open
most of them.)

10
3.6 Text editors

T
AF
Other graphic editors include Dia (used to create diagrams) and Blender
(a 3D graphics tool).
For vector graphics7 Inkscape is available. Its goal is to follow standard
formats such as XML, SVG and CSS.
Scribus is a tool for desktop publishing, computer-aided production of
print media.
Practically speaking, however, the industry standard for graphics is
Adobe’s Creative Suite. Its applications (Photoshop, Illustrator, InDesign,
et al.) are not available for Linux since they are only produced for Windows
and Mac OS X. They are available on most of CSC’s Mac and Windows
DR
systems, albeit with a limited number of licenses.

3.6     Text editors

It is vital to understand the difference between plain text and formatted
text. Plain text contains no type of formatting—no italics, bolds, typefaces,
tables or similar. The only way to “format” plain text is to use whitespace8
and characters like #*_ to emphasise words. Program code is usually
saved in some form of plain text, as are conﬁguration settings.
Programmers have strong opinions (cf. “editor war”) on which text edi-                       8
tor is “the best”. The two main contenders are Emacs    and vi. A proper
editor for software development should have automatic indentation9 and
syntax highlighting.10
Ubuntu’s text editor (Application → Accessories →Text Editor) is called
gedit.

7 In vector graphics, images are built up from lines and curves, making them scaleable

without loss of details.
8 spaces, tabs, newlines
9 Adjusting the left margin with spaces, to distinguish different sections of code
10 Use colors, fonts and such to make the structure visually distinct. Note that this is not

saved in the ﬁle, which is plain text. It is only added on the ﬂy by the editor.

11
Ubuntu

T
AF
Others are also available. Integrated Development Environments (IDEs)
like Eclipse usually contain an integrated editor. Working (due to remote
access or such) in a plain command line environment, you have nano. (On
Solaris, mg is more common.)

3.7     Removable media (USB sticks, etc.)
Ubuntu recognizes most removable media formats. If you plug in a USB
memory stick, it should appear under Places.
Note that before removing the unit, you should unmount it (corre-
sponds to Safely remove hardware in Windows). This is done when you
click the “eject” icon shown next to the unit in the ﬁle manager. Failure to
do so may destroy data on your memory stick.
DR
3.7.1      Printing
You can select a printer in Gnome’s print dialog, and there are also (on the
other tabs) options for duplex (two-sided) printing, which tray to use, etc.
Obviously, the options depend on the printer.

To show the list of documents sent to the print server go to System
→ Administration → Printing, and select View Print Queue by right clicking a
printer.

12
3.8 LTEX
A

T
3.8     LTEX
A

AF
LTEX is a typesetting language that uses a plain text ﬁle written in a
A

markup language 11 developed to describe layout and prepare printable
documents. It is popular in technical and mathematical ﬁelds, since it
has powerful tools to typeset mathematical formulae. There are templates
available for articles, books, letters, presentations, etc.

If $u = f(x)$ and $x = g(\mathbf{t}) = g(t_1, \ldots{}, t_q)$ then
\begin{displaymath}
\frac{\partial u}{\partial t_j} = \frac{du}{dx} \cdot
\frac{\partial x}{\partial t_j} \qquad
\forall j \in \{1, \ldots, q\}
\end{displaymath}
DR
If u = f (x) and x = g(t) = g(t1 , . . . , tq )
then
∂u    du ∂x
=   ·              ∀j ∈ {1, . . . , q}
∂tj   dx ∂tj

This may seem complicated to write, but compared to most alterna-
tives given by various word processors it is a much faster way (with some
experience) to edit text containing complicated formulae.
LTEX by default adhere to appropriate typographical guidelines: the line
A

height is adjusted to be easy to read, appropriate font sizes for headings,
etc. This allows you to focus on writing the content, leaving the formatting
to LTEX.
A

An introduction to LTEX can be found at:
A

The Not So Short Introduction to LTEX2e
A
http://www.ctan.org/tex-archive/info/lshort/english/lshort.pdf
As the name suggests, it is not short, but parts of it can be disregarded
by those who do not need to write Russian, Thai or other foreign languages.

If you don’t want to learn how to write LTEX code, there is also a graph-
A

ical editor based on LTEX, LYX:
A

11 A markup language is a kind of specialized programming language that uses special text

which is not displayed, but changes how the content is displayed. This may be both struc-
tual instructions (separate paragraphs, chapters, etc.), and semantic (describe the relation
between parts of the text: references, quotes, etc.).
Examples other than LTEX and other variants of TEX are HTML, XML and RTF. The formats
A
used for word processors often contain the same type of directives, but as binary codes rather
than as (more or less) readable text.

13
Ubuntu

T
AF
Even if it looks like a common word processor, its philosophy and usage
is different. Very good introductions are available from the Help menu.
DR

14
Mac OS X

4     Mac OS X
4.1   Logging in

T
AF
You log in as usual, using the same computer account as other U NIX
systems. In case of problems, or if the system seems unusually slow, it
may be because your quota is full . In particular, the Library directory
can grow quite large.

4.2   Finder
7.2.2

Most applications can be found in the “dock”, at the bottom of the desk-
DR
top. You can add shortcuts there yourself for those applications you use.
Other applications can be found by starting Finder and choosing Go →
Applications, or the shortcut Cmd-Shift-A.

CSC’s standard applications—M ATLAB, Firefox, Thunderbird—are
available, and work the same as on other OSs. In addition, you have the
normal OS X applications: iTunes, Preview, etc.

15
Mac OS X

4.2.1      Removable media (USB sticks, etc.)

In OS X, a USB unit appears both on the desktop, and among Finder’s
Devices. To remove the unit, drag it to the waste basket on the dock. You
can see that the icon changes to an Eject symbol.

T
4.2.2      Keychain

AF
Keychain is an integrated tool of OS X, that keeps track of various pass-
words. Apart from the password you use to log in, you may need to use
passwords for web pages, network connections, wireless networks, en-
crypted ﬁles, etc. In Keychain, these are stored (encrypted), and applica-
tions kan fetch them when needed.
When you use a password in a Keychain-aware applications, a popup-
dialog will ask whether you want to save it:

If Keychain starts to ask for you login password, its settings may have
been corrupted.1 In that case, you may need to remove your keychains;
see the webpages of Systemgruppen, the KTH CSC Systems Group.
DR
• How to remove your keychain
http://www.kth.se/dokumentation/it-support-csc/environment/mac/instructions/keychainremove

• How to change the password for your keychain
http://www.kth.se/dokumentation/it-support-csc/environment/mac/instructions/changekcpasswd

4.3        Internet
OS X’s web browser is Safari. You will ﬁnd it in the dock.

1 This   is often because you have hit your quota limit   7.2.2 .

16
4.4 Ofﬁce applications

4.4     Ofﬁce applications
4.4.1   iWork
Apple’s ofﬁce suite is called iWork. Its ofﬁce applications are probably most
closely integraded with the core applications of OS X. The components are:

T
Pages for word processing and page layout.
Numbers for spreadsheets (calculation, data tables, charts, etc.).
Keynote for presentations.

AF
DR
4.4.2   MS Ofﬁce 2008

All CSC macs also have MS Ofﬁce 2008 installed. It has more or less
the same core components as the Windows version:

Word for word processing.
Excel for spreadsheets.
Powerpoint for presentations.

17
Mac OS X

There is also Entourage, an email and personal information manager
(replacing MS Outlook, which is not available for OS X). However, Entourage
is not installed on CSC’s computers.2

4.4.3       Plain text; LTEX
A

T
To write simple texts, and plain text, you can use TextEdit.
3.8      For LTEX the Macs, like the Ubuntu machines, run TEXLive. The
A

command line programs for LTEX A        should thus work the same as on
Ubuntu. There is also a graphical environment for writing LTEX code,
A

TEXShop.
The latter has one window to write the code, and another to display the
result.

4.5        Graphics
AF
4.5.1       The Adobe suite: CS5
DR
Adobe Creative Suite, version 5, or CS5, is installed on all computers. The
details of how these applications work is—to say the least—beyond what
this document can address, but the applications deﬁne the standard for
graphics editing. Documentation can be found both online and in print.
The most common among the many applications are:
Photoshop to edit photos, or other raster graphics (“pixel” images)
Illustrator to edit vector graphics
InDesign for desktop publishing or other creation of printed media
(posters, brochures, books, . . . )

4.5.2       Other applications (selected)
Autodesk Maya is used to create 3D animations, model, simulations, vi-
sual effects and such. Used in movie and TV industry, but also to
create computer games, architectural models and other design.
Final Cut Pro is used to produce videos and movies. Has been used for
many large Hollywood movies, but is also popular among smaller in-
dependent ﬁlmmakers.
Adobe Dreamweaver 3 is used for web development. Most useful when
maintaning entire websites, with builtin tools for ﬁle transfer and
synchronization. Has both a what you see is what you get interface,
and the ability to edit the code directly.
2 It   stores its data in a way that does not work well with a home directory under AFS.
3 Originally    Macromedia Dreamweaver.

18
4.5 Graphics

4.5.3   Printing
Most applications use OS X’s print dialog. You don’t to do more than
select which printer to use, but the popup menu also gives access to other
options.

T
AF
You will ﬁnd the printer queue by going to System Settings and there
choose Print & Fax.
DR

19
Solaris

5     Solaris
5.1     Logging in
The login screen of a Solaris system allows you to choose among the

T
various window environments. Java Desktop System (JDS) is based on
Gnome, but built to have a somewhat more Windows-like appearance. You
can also use Common Desktop Environment (CDE). This was previously the
default environment at KTH CSC, and many still use it.

3.1.1
5.1.1
AF
Failsafe login (in case of problems)
As shown in the login screen above, Solaris (like Ubuntu ) allow you to
log in to a failsafe session. This will only open a terminal window, the
DR
equivalent of Ubuntu’s Failsafe option.

N.B! You will need to keep the mouse pointer over the terminal window,
otherwise it will not have focus (accept keyboard input).

5.1.2   Thin clients (SunRay terminals)
The only Solaris systems that remain in the computer rooms are not com-
plete workstations, but thin clients. That is, what you see on the table is
not an entire computer, but only a unit with keyboard, mouse and screen.
All software is run on a central server, shared among the users of the
thin clients. This has many advantages—e.g. the clients are completely
silent—but some things need to be taken into consideration
You must log out. Simply powering off the client will not log you out.
When it is turned on, you will still be logged in; your programs will
continue to run.
If you have trouble logging out, use the keyboard shortcut
Ctrl-Alt-backspace backspace (keep Ctrl and Alt pressed down,
press backspace twice). This will kill your session. All applications
will be killed as well, and unsaved ﬁles may be lost!
Resources are shared. If the programs you run require a lot of memory,
bandwidth, or other resources, it will affect the programs of other
users.

9.2.1   Certain programs may require special handling. E.g., I DLE (an applica-
tion used for Python programming ) must be run with idle -n if
run by all users simultaneously.

20
5.1 Logging in

5.1.3    Java Desktop System (JDS)
Java Desktop only have a single panel (at the bottom of the screen, unless
you move it), where applications and settings are found as submenus,
rather than being main menus next to one another. (The Launch button

T
works similar to MS Windows’ Start button.)

AF
The Solaris system at CSC has been developed over many years. In
order to still be able to use old applications and programs, the Solaris
system uses modules to a larger extent than others. Hence, apart from
standard tools, you will have to ensure that modules for those applications
you desire are loaded when you log in, and add any launchers you desire
7.1.8

to access them.1
For example, to create a desktop icon for starting the G IMP application,
DR
right click the desktop and choose Create Launcher.

You need to know what to enter in the text ﬁelds. The command that
runs the application is gimp, so open a terminal and check:

> which gimp
no gimp in /usr/local/bin /usr/local/bin/X11 [...]

Unfortunately, no gimp is available since it requires a module. So,

> whichmodule gimp
Module commands which gives access to different
1 You can of course also run applications from a terminal, after adding the necessary mod-

ules when and if needed.

21
Solaris

versions/variants of the command "gimp":
module add csw   (= module add csw/SunOS-5.10)
Alternative: csw/1.2
csw/1.3
module add hacks   (= module add hacks/0.0)

T
module add sfw   (= module add sfw/5.10)

> module add csw

> which gimp
/opt/csw/bin/gimp

Then you can enter what is needed.2

AF
5.1.4       Removable media (USB sticks, etc.)
Since many thin clients use the same computer (physically located in a
server room), handling of USB media is somewhat complicated. Media are
mounted under a subdirectory to /tmp/SUNWut/mnt/ named with your
username. In a subdirectory to that, you will ﬁnd all media that you have
mounted.
To remove the media, use the command3

> /opt/SUNWut/bin/utumount \
-u /tmp/SUNWut/mnt/«username»/«directory»

N.B! Filenames with non-english characters, e.g. Å, Ä, Ö, may cause
problems. It’s best to limit ﬁlenames to “normal” (i.e. English) characters.
Spaces work, but may make it more difﬁcult to work on the command-line.
DR

2 The    icon is /opt/csw/share/icons/hicolor/scalable/apps/gimp.svg.
3 If   everything is written on one line, the \ is not needed

22
The U NIX command-line

6     The U NIX command-line
You can use a terminal to move ﬁles, create or remove directories, and
so on. This is done by entering commands, which are then performed
by the computer. For someone who has never worked in this fashion, in a

T
Command-line Interface, or CLI, it may seem primitive to type commands in
order to see the contents of a directory. Well, with modern U NIX system, all
such “common” tasks can be done with a ﬁle manager or similar. Graphical
tools are available for almost all everyday tasks, and the average user only
needs the CLI for “unconventional” work, if that.
There are however advantages to a CLI, and learning how to use one is
recommended for all students taking any course dealing with some form
of programming. If you are reading this, you are presumably doing so.

AF
6.2
One of the ﬁrst commands you should use is kpasswd to change your
password. Other commands are given in section 6.3, which can be used
as a reference manual.

Some advantages of a CLI (command-line interface)1 :

• You can work very rapidly. Though difﬁcult to master, once you have
learned how to express your ideas that way, a CLI allows you to do so
very quickly.
Compare using keyboard shortcuts like Ctrl-O, rather than catching
the mouse and direct it to File → Open.
• Remote access (network access) within a CLI is scarcely any different
from using it locally. It also requires far less in terms of network
resources than graphical alternatives.
• Instructions can be given concisely. Although the same task is per-
formed, it is easier to say (or write) “Type rm -rf /.mozilla/ in a
terminal,” rather than
DR
Open a ﬁle manager. Go to your home directory by clicking
Home on the toolbar. Show hidden ﬁles by choosing View →
Show Hidden Files. Select the directory .mozilla. Right click
and choose Delete.
• You can make your own scripts. A script is a sequence of commands,
which are performed just as if you wrote them in a CLI.2
Since a script can be called just like a builtin program, you make no
difference between “user ﬁles” and “builtin programs.” This makes it
easy to extend a U NIX system with your own tools and applications.
There is a reason why U NIX is popular among programmers.

When working on the command line, you need to structure your
thoughts so that tasks can be performed in a sequential manner. The
steps are often the same as those performed in a GUI, but may be
performed by calling several different programs. Suppose you wish to
print a few ﬁles. You need to:

1. Go to the directory containing the ﬁles. (Command: cd)
2. List all ﬁles. (Command: ls)
3. Send the appropriate ﬁles to the printer. (Command: various3 )

1 There are command-lines in most OSs; Windows has the older command prompt, and

the newer PowerShell. We will however deal exclusively with U NIX-type command-lines.
2 A script   7.1.3 is more or less a small program. The difference between what is con-
sidered a script or a program is vague, depending more on how complicated the code is than
on any technical difference.
3 Done differently, depending on the ﬁles’ contents.

23
The U NIX command-line

Learning the use of a CLI consists partly of learn-
ing some of the most common commands, partly of
learning how program interaction should be set up to
perform a task.
One of the most important tools for inter-

T
7.1.5   process communication (as this is usually called) is
redirection .

6.1    Basics: shell, prompt, path
There are several different shells, i.e. programs that interpret your com-
mands. All new accounts at KTH CSC are set to use bash, but older ac-
counts used tcsh. The commands in this chapter work the same in both,
but the concepts adressed in the next chapter may be performed differ-

AF
ently depending on which shell is used.

The ﬁrst thing you will see when opening a terminal is the prompt. In
general, it is
user@host:path>

where host is the name of the computer you are using, and path is the di-
rectory you are currently in (more on that later). The prompt’s appearance
10.5.4   may be altered; if you see anything else, you are not using CSC’s default
settings. See Restore default settings .
To save space, we will use a more concise prompt, >, in those cases
when you don’t need to know the host name or path. We may also use
user:path>, if we need to show which user does what.
7.1.4      There are several tools builtin to the shell to help you. One of the most
important is tab completion .

6.2    Change user password (kpasswd)
DR
If you have not already done so, you should use kpasswd4 to change the
(randomized) password you have been issued to something easier to re-
member. The command will ﬁrst request your old password, then the new
one twice. You will not see any indication that you are entering text. Neither
the characters you type, nor any other symbol, will be shown to represent
the keystrokes.
kpasswd will reject the new one (and show an error message) if it is
too simple. You should use some uppercase letters, some lowercase, a
number or character such as &/()+!-,., etc. No whitespace, however,
nor non-ASCII characters like ÅÄÖ!
Note that most KTH users have several different computer accounts.
You can (mostly) choose the same password in the various systems, but
you need to remember that changing the password in one place, will not
automatically do so in all others.

6.3    Commands
The names of U NIX commands are often short, so that typing them is
quick. If the system was created today, it might be built such that you
could call commands both with long and short names, i.e. write either mv
or move. At the time (’70s and ’80s) computers were not only slower, it
was also before you could “waste” expensive memory on such frivolities, or
luxuries such as command history.
The motivation (or mnemonics) for some of the most common com-
mands5 can be found in Table 1.
4 On the Solaris systems, you previously used passwd, which also gave some hints on how

to choose a good password. passwd will still work, but only on the Solaris systems.
5 Motivation for some of the more advanced names can be found on a Usenet FAQ for

24
6.3 Commands

Command            Mnemonics                        Usage
cd             change directory        change the working directory
pwd            print     working       show the current path
directory
mkdir          make directory          create directories

T
rmdir          remove directory        remove (empty) directories
mv             move                    move ﬁle/directory
cp             copy                    copy ﬁle/directory
rm             remove                  remove ﬁles, with -r also (non
empty) directories
cat            concatenate             show text ﬁles on the screen
more           -                       show text ﬁles, one page at a time
less           -                       less is more—likewise, but with
more functionality

AF
ln [-s]        link                    create (symbolic) links
fs             file system             AFS command and access rights
chmod          change mode bits        U NIX access rights
man            manual                  documentation (see page 54
10.1 )
apropos        -                       look for command by keywords
(see page 55)    10.1

Table 1: Common U NIX commands

You can ﬁnd more extensive documentation than this document pro-            10.1
vides, by looking at the respective commands’ man pages (manual pages
are shown with the command man, hence the name).
You can change the behavior for most commands by using an option
argument (a.k.a. parameter or ﬂag). For example: ls -a shows hidden
ﬁles as well.
DR
6.3.1   Navigating in the ﬁle system (cd och pwd)
For more information on how directories are organized, see the section on      6.4.2
the ﬁle tree .
Since you don’t always want to use the absolute path (given from the
root of the ﬁle system), you usually give a relative path, starting from the
directory that is your current “location.” If your current working directory
is your home directory ~, then Private/README is the ﬁle README in the
subdirectory Private, i.e. ~/Private/README.
To change directory, you use cd:

dator:~> cd Private
dator:~/Private> cat README
[...]
dator:~/Private> cd /usr/local/
dator:/usr/local> cd ..
dator:/usr>

To help you remember the current location, the working directory is
also given in the prompt. To show the absolute path (rather than relative
to your home directory), use the command pwd.
In the same way you can use .. (dot-dot) to go “up” (one step back in
the ﬁle system’s hierarchy), you can use . (dot) for the current directory.
Normally not needed—there is no reason to say cd ./Private when cd

U NIX:What does {some strange unix command name} stand for?
http://www.faqs.org/faqs/unix-faq/faq/part1/section-3.html
Usenet, or newsgroups, is a text based online discussion system.

25
The U NIX command-line

Private works. But if you are copying ﬁles to the current directory, you
use . to specify the target.
You can also go up several level at once. Suppose you are in the direc-
tory numerical in the ﬁle tree shown to the right.
Then you can use the following sequence of

T
commands to go to the directory lab1, then up
one step and down into lab2.

dator:~/numerical> cd labs/lab1
dator:~/numerical/labs/lab1> cat example.m
[...]
dator:~/numerical/labs/lab1> cd ../lab2/
dator:~/numerical/labs/lab2>
7.1.4

AF
Some judicious use of tab completion                could be used to save you some
typing.

6.3.2      List ﬁles (ls)
To see what ﬁles are contained in a directory6 you use
> ls [directory]

To separate ﬁles, directories etc. from another, use the option -F or
--color. The ﬁrst adds a character after the ﬁle name, the other displays
it with a distinguishing color. The most common ﬁle types are
Character       Color                  Type
*           green     command (executable ﬁle)
/             blue     directory
@            cyan      (symbolic) link
7.1.6
Most systems help you by setting an alias , so that one of these options
is given automatically whenever you enter ls.
DR
There are many settings intended to help you, so that you don’t need to
7.1.4   enter non-necessary details, or stop typing a command just to ﬁnd a ﬁle
name (and then retype it again). The shortcut «tab»«tab» (tab comple-
7.1.2   tion ) can often be used instead of calling ls.
You can also use wildcards     to list “everything starting with ‘a’,” or
(more complicated) “everything in the ‘labs’ subdirectory starting with ‘lab’
and ending with ‘.m’”:
> ls a*
> ls labs/lab*.m

Filenames starting with a period, “.” are hidden, i.e. not shown when
listing ﬁles, nor in a ﬁle manager. To see these ﬁles, use the option -a.
To see ﬁle sizes, modiﬁcation date, and more information, use ls -l.
There are many, many other options. ls --help shows two pages(!)
10.1    with the most common ones. For even more, and details not show by
--help, see the man page .

6.3.3      Create and remove directories (mkdir and rmdir)
mkdir creates directories. As always, you can use long paths, should you
want to
> mkdir new_directory
> mkdir /long/path/to/new_directory

rmdir removes a directory, but it must be empty. Nor can it contain any
6.3.5   hidden ﬁles (starting with “.”). It is therefore common to instead remove di-
rectories with rm , which has an option to remove directories recursively.
6 The   current directory is assumed, unless another is speciﬁed.

26
6.3 Commands

6.3.4    Move and copy ﬁles (mv and cp)
To move a ﬁle, or rename it (which is considered a special case of moving
it), use mv. To prevent from accidentally overwriting a ﬁle, form the habit of
using -i. Then you will be prompted rather than having ﬁles accidentally

T
overwritten.
Copies are made by cp. You can copy directories and their contents
(recursively) with -r, but mistakes are easily made. What does it mean                      6.3.8
to copy a link ? Do you get a new link, or a copy of its target? Other
commands (tar, rsync) can make recursive copies more safely. It’s better
to see the documentation, rather than make a mistake. cp also has a -i
option.

6.3.5    Remove ﬁles (rm)

AF
Files are removed (deleted) with rm. The option -r can remove entire di-
rectories recursively, i.e. ﬁrst remove the contents7 , and then remove the
directory.

Warning! Using -r can be very dangerous. The classical way to shoot
yourself in the foot (make a mistake), is to say
Warning
> rm -r . thumbnails/

when you wish to remove the directory .thumbnails. Since you acciden-
tally put a space after the leading period, everything in the current directory
is removed—you wrote rm -r .. Then, you get an error message since
there is no directory thumbnails/ to remove.

6.3.6    Show text ﬁles (cat, more, less)
DR
The cat command displays the contents of ﬁles (usually plain text ones).
If more than one ﬁle is given, they will be concatenated (merged) and all
ﬁles are displayed. (Hence the command name.)
If the contents can’t be shown on a single page of the terminal, you can
use the more command to page through them. Although more has facilities
for e.g. searching (press / and enter the search term), you cannot “back
up” pages. Many therefore use less instead8 Unlike more, which exits
automatically when you reach the end of the (last) ﬁle, in less you must
explicitly use q to exit.

6.3.7    Printing
You can print most documents graphically, from within the application
used to create them. Usually, by going to File → Print. . . . For more informa-
tion on this, see the respective computer environment.
To print a plain text ﬁle, use the command a2ps. You may (depend-
ing on the printer settings) need to specify the media as A4 paper (the
American “letter” is usually default).

> a2ps -M A4 -1 filename
2.2
Note that the ﬁle must have the correct encoding . Otherwise charac-
ters like ÅÄÖ will be printed incorrectly. If your ﬁle uses UTF-8, you can
print it with9
7 “Recursive”, since if there are any subdirectories, these must ﬁrst be removed, which

means their subdirectories must be removed. . .
8 less was created after more, with more capabilities. “Less is more.”
9 The backslash is used to continue the command on the next line; doing so is optional.

27
The U NIX command-line

> iconv -f utf-8 -t latin-1 < filename
| a2ps -M A4 -1

See the man page for a2ps to learn more about its options.

T
When you send a job to the printer, it is placed in a queue. You can
show the queue with the command

> lpq

Most prints should probably be made on the closest printer. When you
log in, the printer in that room is set as the default printer. Both a2ps and
lpq understand the option -P printer, for using another printer. The
printers are generally named after the computer rooms. For example, red

AF
is the printer för the room Röd (Swedish for red), musik is the printer for
the room Musik.
You can also send a ﬁle directly to the printer, using lpr, but unless
you know that the ﬁle is a PostScript ﬁle10 you may recieve page after page
of strange characters, rapidly emptying your print quota.
To remove a print job from the queue, use

> lprm Job_ID

where Job_ID is a number shown by lpq.

6.3.8    Symbolic links (ln -s)
A symbolic link11 is a ﬁle that “points to” another ﬁle. Using them, you can
access the same ﬁle (or directory) from multiple places in the ﬁle system,
without creating copies. Suppose you and a fellow student wish to work
on the same program. If you create a link, numerical, pointing to his
directory, then you can both access the ﬁles without you having to navigate
DR
to his home directory.
An important difference between symbolic links and the so-called short-
cuts of MS Windows, is that a program does not need to be coded to take
special measures when opening a link. Support for symbolic links is there-
fore global—it is integrated to the entire system, rather than the individual
application.
Unlike Mac OS X’s alias, you cannot move the target pointed to by a
symbolic link.

Example: Suppose alice wish to work
with bob in his directory numerical. She
can then create a link to the directory, and
access the ﬁles through that.
Note the difference of listing the link (ls
numerical) and listing the contents of the
target directory (ls numerical/). Also, it
is important to understand that alice does
not have copies of bob’s ﬁles. If she makes
changes to lab1.m, bob will see them, and
if bob moves or removes his directory, alice
will no longer be able to access the ﬁles.
10 PostScript   http://en.wikipedia.org/wiki/PostScript
11 A non symbolic link, or hard link is created when the -s option is not used. A hard link
is the reference used by the directory to associate a name with the binary data stored in the
ﬁle system. A ﬁle may have multiple hard links, and the data will not be removed until the
last one is deleted. (Symbolic link, on the other hand, may point to a ﬁle that does not exist.)
Hard links are not supported (across directories) by AFS, and are rarely used at CSC.
Since their use may involve some risks, other similar mechanisms are often used instead.
E.g. junction points under NTFS (Windows), or alias under Mac OS X.

28
6.3 Commands

> ln -s ~bob/numerical numerical
> ls -F numerical
numerical@
> ls numerical/
numerical/lab1.m

T
numerical/lab3.m
> cat numerical/lab1.m
[...]
> ls -l numerical
[...] numerical -> /afs/nada.kth.se/home/5/u1qbad95/numerical

Understanding all the details of the above example requires careful
scrutiny. For example, translation of ~bob into his home directory /afs/

AF
... is done by the shell; “∼bob” is not part of the link. Symbolic links can
also cause some complex situations. Suppose bob creates a link inside the
directory numerical that uses .. (the parent directory). What happens
when alice uses that link? Will she access her own home directory, or
bob’s? Which of the following will work? Both?

> cd numerical/
> ln -s ../graphics bob-course
> ln -s ../progintro alice-course

When you understand why one works, but not the other, you have
understood much of the intricacies of U NIX ﬁle handling.

Pitfalls:
• If you copy a link, you get a copy of the target. The option -d of
Ubuntu’s cp avoids this, but this option is not available in e.g. So-
laris’s cp (unless you use GNU’s cp; both versions are available). Bet-
DR
ter: use tar or rsync.12
• Overwriting a link (i.e. copying or moving a ﬁle to the link’s ﬁlename),
will overwrite the target. Options can alter this as well, but be careful!

6.3.9    Access rights (fs, chmod)
7.2
Most of your ﬁles at KTH CSC are stored under the ﬁle system AFS 13
where access rights work slightly different to traditional U NIX permissions.
They are set on a directory (not ﬁle) level, using the fs setacl command
(abbreviated fs sa14 ) and are displayed with fs listacl (or fs la).

fs sa directory user access_rights
fs la directory...

The access rights are shown in Table 2.
Example:
> fs la
Access list for . is
system:administrators rlidwka
system:anyuser l
alice rlidwka
bob rl
charlie rlidwk
12 Being complex programs, neither is explained in this document. It’s better that you ask

for help    10.3 regarding them.
13 AFS (Andrew File System) http://en.wikipedia.org/wiki/Andrew_File_System
14 ACL stands for access control list

29
The U NIX command-line

Meaning         Description
r    read            Read the contents of the directory’s ﬁles
l    list            List the ﬁles in the directory
i    insert          Create new ﬁles in the directory
d    delete          Delete ﬁles from the directory

T
w    write           Modify the contents of the directory’s ﬁles
k    lock            Lock ﬁles in the directory
a    administer      Change the ACL of the directory

Table 2: AFS access rights

Here, alice has full access rights, as does the group sys-

AF
tem:administrators.15 bob can read all ﬁles, but not change the contents.
charlie can read, change and delete ﬁles, but cannot himself change the
access rights. All users (system:anyuser) can see what ﬁles the directory
contains, but not read their contents.

> fs sa ~/kurser/numerical bob rlidw
> fs sa ~/kurser/numerical charlie none

This gives bob permissions to change the (contents of) ﬁles in the direc-
tory, and removes all access rights for charlie. Apart from the individual
letters, you can use read (equivalent to rl), write (rlidwk, all except a), all
(rlidwka) or none (remove the user from the ACL).

When a directory is created, its ACL is copied from the containing direc-
tory. Changing an ACL will not affect the ACLs of existing subdirectories.
So, if you wish to give access to a colleague, you should probably ﬁrst set
the access rights, then create subdirectories.

You may also need to modify the traditional U NIX permissions.
DR
The U NIX ﬁle system (UFS) has long since had three distinct classes:
user (the ﬁle’s owner), group, and other (everyone else). For each class,
you set the permission to read, write or execute the ﬁles (or open the
directory).
These permissions are shown by ls -l, or in the ﬁle manager:

> ls -l notes.txt
-rwxr-xr-x 1 alice usr               187 Apr 3 14:37 notes.txt

The permissions -rwxr-xr-x are16 divided into the three classes:

user    group      other
rwx      r-x        r-x

where the permissions are

Meaning       Gives permission to
r    read          read the ﬁle contents
w    write         write to the ﬁle (change its contents)
x    execute       execute the ﬁle as a command

To add or remove permissions, you can use

> chmod +permissions file_name
> chmod -permissions file_name
15 The group system:administrators contains the admins of the volume’s local cell. Thus,

administrators for the cell nada.kth.se are not given access to the cell athena.mit.edu. You
can create your own groups with the pts command.
16 Except for the ﬁrst dash, which represents something else

30
6.3 Commands

but the full syntax used for the command is

> chmod [references][operator][modes] filenames...

where references determines if you mean user/group/other, operator sets

T
or removes permissions, and mode indicates read/write/execute17 .
It is also common to (as when programming in the C computer lan-
guage) give the permissions with three or four octal digits.18 For example,
to remove the execute ﬂag on alice’s ﬁle above:
> chmod 0644 notes.txt
> ls -la notes.txt
-rw-r--r-- 1 alice usr 187 2010-04-03 14:37 anteckningar.txt

AF
UFS permissions are still used for local ﬁles, i.e. those stored on the
computer’s local hard disk. Also, AFS uses the user part of the permis-
sions. Thus,

To       you need AFS       and permission
write        write (w)           write (w)
remove        delete (d)          write (w)
execute        read (r)          execute (x)
read          read (r)            read (r)

Warning: To read ﬁles, you must not only have the access rights, you
must also be authenticated. This is normally done when you log in; you
are then given Kerberos tickets that last for 10 hours. If you remain logged
in for longer than that, you may need to use the kauth command to get                    7.2.1
new tickets . Tickets are listed with klist.
Exceeding your quota may also prevent you from saving ﬁles.                           7.2.2
DR
6.3.10   Display text (echo)
To display a line of text in the terminal, you can use echo, or in some                  7.1.5
circumstances cat. This is mostly used for redirection and scripting
7.1.3
6.3.11   Programs and processes (kill, fg, bg)
When a program is run, the instructions stored in the program’s ﬁle are
executed. These instructions are executed in one or several processes.
When a program (in this case, an application) is run as

> firefox

your prompt will disappear until the application exits. This is called run-
ning in the foreground, and the program is the current process. If an appli-
cation opens a new window, this is unnecessary. You can instead run it in
the background:

> firefox &

If a program is accidentally run in the foreground, and you wish to
move it to the background, you can suspend it with Ctrl-z. This shows
the message “Stopped”, and the program halts (temporarily). If you then
enter bg, it starts again, now as a background process.
17 For a more detailed description, and more examples, see Wikipedia’s page for chmod

http://en.wikipedia.org/wiki/Chmod
18 To understand how this works, see the Wikipedia page for ﬁle system permissions

http://en.wikipedia.org/wiki/File_system_permissions#Octal_notation

31
The U NIX command-line

You can also terminate a forground process with Ctrl-C. Note, how-
ever, that the program might not save open ﬁles, clean up temporary data,
etc. You should only do this when you can’t exit the program normally.
A process running in the background can be resumed in the foreground
using fg. Both bg and fg can take an argument, %n, where n is a number

T
specifying the process (given by jobs, and shown when you press Ctrl-z).
The same argument can be given to kill, which terminates a process
much like Ctrl-C (and with the same risks).
A process that has been started in another terminal, or any other fash-
ion, is not shown by jobs. But you can use top. It shows the running
processes, by default ordered after how much processor time they are
presently using. The column PID gives the id for the process. It can be
used as an argument to kill (with no leading %).
There is also a command, xkill, which lets you select a window to kill

AF
the program that uses it.
There is much to say about processes, and the handling of them, but
we will instead refer to the man pages for kill, top and ps (another program
that displays current processes).

6.4     Concepts
6.4.1    Command, argument, option
A command line consists of a command, followed by one or more argu-
ments. One particular type of argument is an option (a.k.a. parameter,
ﬂag). Loosely, the command says what to do, the option how, and the
arguments on what, or where.
Arguments are separated by one or more spaces. If an argument should
contain spaces, you need to quote it (surround it with single or double
quotes) or use a backslash in front.19

> command "one argument"
DR
> command ’one argument’
> command one\ argument

Options are often one letter (“short option”, or “ﬂag”) with a leading
”-”, or a word (“long option”) with a leading ”--”. Most commands accept
that short options are grouped together (-sF is equivalent to -s -F). Most
options are given before all other argument, but there are exceptions.
Options may also have an argument:

> find Private/ -type d

The command ﬁnd is given the option type with an argument, d (for
directory). Private/ is (here) one of the “other arguments.” You may note
that ﬁnd is an exception both to the rule that long options starts with two
dashes, and that the options precede “other arguments.”
Both commands and arguments are case sensitive. FIND is not the
same thing as find, and there is no option called -Type.
To know what options/arguments should be given, you can call most
10.1   commands with -h, --help, -? or similar. There is also more extensive
documentation available, usually as a man page .
Output is rare, except when requested. In other words, if a command
failes to e.g. create a directory, you will be given a (somewhat cryptic)
error message, but if the commands succeeds, nothing is shown. You will
simply be returned to the prompt. Remember,

“No news, is good news”
19 Whether to use " or is optional, but on some occations make a differenct. Note that a

backslash, “\” is not the same character as a slash, “/”.

32
6.4 Concepts

6.4.2      The ﬁle tree
Data storage is organized in ﬁles. A ﬁle contains binary data. The data may
represent anything—it could be an executable program, but could also be
a text document, a video, etc. All characters except “/” can be used in a

T
ﬁle name, but characters such as linebreaks or ; may be difﬁcult to type.
It does not matter to the ﬁle system what the ﬁle contains—text, images,
audio, etc—that is something the applications can deal with.
Files are organized in directories (a.k.a. folders). By placing directories
inside directories, you achieve a tree-like structure. Most ﬁle managers
can show ﬁlesystems as such:

AF
The top-most directory (that contains all other directories) is the root,
and is usually referred to with a single slash, /. Other directories are
referred to by name, separated by slashes. To describe where a ﬁle (or
directory) is located in the ﬁle system, you start at the root, and name the
directories and subdirectories that take you there. This is called a path,
and may look like:

/var/tmp/readme.txt
DR
which means that the ﬁle readme.txt is in the directory tmp, which is in
the directory var, which is in / (the root). To show the contents of this ﬁle             6.3.6
with the command cat , you enter

> cat /var/tmp/readme.txt

Note that removable units (CDs, USB sticks) are inserted somewhere in
the ﬁle system (usually somewhere under /media/). This is typically done
automatically; you say that the unit is mounted at a mount point.

Apart from the root, there are some other special directories:

~       Your home directory, containing your ﬁles and settings. You can
also access the home directories of others, by ~name, e.g. ~alice/
README-AFS to access a ﬁle in alice’s home directory
.       Current (working) directory, see below.
..      Parent directory, “one step up”

While you can store ﬁles in other places than your home directory,
having a dedicated area helps to separate ﬁles that you own from the ﬁles
of others, or the system ﬁles.
Smaller U NIX systems usually keep home directories as subdirectories
of /home, e.g. /home/alice. Since KTH CSC has over 25,000 users, this
would be impractical. Also, home directories are stored on AFS, so you
will instead ﬁnd them under20
/afs/nada.kth.se/home/3/u1ak8b73/
20 The   somewhat cumbersome part with u1xxx is taken from a central database with KTH
ids.

33
The U NIX command-line

You can often skip the top two directories, /afs/nada.kth.se and in-
stead use /home/3/u1ak8b73/.
If you are using a ﬁle transfer program, or for some other reason can’t
enter the path as ~username, there is also a directory structure based on
the username,

T
/afs/nada.kth.se/home-by-name/«x»/«y»/name/

where x and y are the ﬁrst two letters of the username, e.g. /afs/nada.
kth.se/home-by-name/a/l/alice/.

The most common directories are given in Table 3
The different directories /bin, /usr/bin, and /usr/local/bin (and
the same for sbin and lib) are mostly there for those who administer

AF
many computers. Three levels of mostly equivalent structures are used.
Programs are for example stored in:

1. /bin which contains essential system binaries. These are needed
for single user mode (failsafe mode, used mostly for system mainte-
nance).
2. /usr/bin containing “non-essential”21 binaries that are not system-
speciﬁc, i.e. modiﬁed for the speciﬁc computer. This directory can
be placed on a network unit, but for performance reasons this is not
done on CSC’s computer. Most applications live here.
3. /usr/local/bin containing programs that are speciﬁc to this com-
puter.

Directory                                Description
/                root of the ﬁle system (level 1)
/usr             “non-essential” data, not needed for booting (level 2)
DR
/usr/local       host-speciﬁc data (level 3)
/bin             system essential binaries (also under level 2–3)
/sbin            system essential adminstrative programs (also level 2–3)
/lib             program libraries for /bin
/dev             “ﬁles” representing hardware
/etc             conﬁguration ﬁles
/home            home directories
/media           temporary media such as CDs, USB media, etc.
/tmp             temporary ﬁles (contents will not be retained between
system reboots)
/var             variable ﬁles—expected to change during normal oper-
ation (logs, ﬁle locks, printer queues, etc.)
/var/tmp         temporary ﬁles (cleaned out occationally)
/opt             certain add-on software

Table 3: Directory structure (selection)

6.3.9
To set permissions and access rights, you use chmod     (under UFS,
6.3.9   U NIX File System or fs sa     (under AFS). UFS handles permissions on
each ﬁle, AFS only on the directory level.

21 I.e., they are not essential for system maintenance; you can boot the system without

them.

34
Details

7      Details
7.1      More about the command-line interface
7.1.1     Command history

T
Re-entering a command line just to correct a single character type is cum-
bersome. The shell1 will remember what commands you have given, and
you can recall previous commands with «up arrow».
The entire history is shown by history, and you can search backwards
with Ctrl-R. Other shortcuts can be used to cut, paste and edit. Most
shortcuts are borrowed from those of the Emacs editor, and the shell’s
documentation uses that terminology. Therefore, look for C-r rather than
Ctrl-R, or M-u rather than Alt-U for the command that transforms the

AF
following word into UPPER CASE.

7.1.2     Wildcards
Most will have seen what *.txt means—all “text ﬁles”, i.e. ﬁles ending in
.txt. U NIX also uses ? to substitute for any one character2 and lets you
create groups of characters using []. In other words, the group [aeiou]
would match all (English) vowels3 , and [a-z0-9] all (lowercase) letters
and numbers.4
The example below opens (only) the two ﬁles final.pdf and penguin.
pdf in Document Viewer (which is run by the command evince).
> ls
README.txt    final.pdf
penguin.pdf   Tux-G2.pdf
> evince [a-z]*.pdf &

Note that *.* are not “all ﬁles.” It would match neither (1) readme (no
period), (2) .readme (leading period), nor (3) readme. (nothing trailing the
DR
dot).
If you wish to use a special character as a normal character, you need
to escape it:
> echo A * is born
A Desktop Documents OldFiles Private
Public README-AFS is born
> echo A ’*’ is born
A * is born

For this, use
’argument’        Protects every character except ’.
"argument"        Protects every character except " and $. \x Protects x from special treatment, where x is (nearly) any character. 7.1.3 Script A script is a program that is not compiled from source code, but consists of a plain text ﬁle that another program interprets line by line.5 The ﬁrst line of a script often starts with a so-called “shebang”—the special sequense #! followed by the path to the program that should interpret the script. An example of a minimal script: 1 whichinterprets what you write, ﬁnds the applications and run them 2 Exceptfor slash, /, which must be written explicitly, or . at the start of a ﬁlename. 3 “Y” and “W” are sometimes considered to be vowels or semivowels in English, but not always. 4 The dash represents “all characters between,” but the order is not obvious. It depends on the encoding, see ASCII http://en.wikipedia.org/wiki/Character_encoding 5 You can talk about e.g. M ATLAB and Python programs as scripts, but usually you mean those scripts run by a shell, i.e. sh, bash, tcsh etc. 35 Details #!/bin/sh file /usr/bin/* | grep -i script T More advanced scripts can handle arguments, show GUIs, etc. They are built using the if, while and for constructs normally found in program- ming. Many use pipelines (see below), and there are many small tools that can be used to rearrange words and such. For example, using ... | tr -c -d ’A-Za-z ’ | ... AF would remove everything except (English) letters and spaces. 7.1.4 Tab completion Tab completion is used to avoid the tedious typing of long ﬁlenames, or to conﬁrm that you haven’t mistyped a path. The shell will automatically ﬁll in partially typed paths. If there are two ﬁles, called readme.txt and read_this_first.txt, you can type > mv -i r«tab»m«tab» After the ﬁrst «tab», the name will be completed as far as possible, i.e. to read. After this, it is no longer unique; it may completed by me or _this. . . . When you enter m, the name is unique, and the next «tab» completes the ﬁlename. If you press «tab» twice, the possible completions will be listed. This DR also works when a directory is given (including the slash). Then all ﬁles in the directory are listed. Using «tab»«tab» will quickly become a habid, to ensure that the computer can ﬁnd the ﬁles you assume are there. Tab completion can also be found in other applications; most text edi- tors have some form of it. 10.5.2 If you use tcsh, things work slightly different. The traditional CSC set- tings are to not use «tab» but ?. See the section on old settings . 7.1.5 Redirection If a terminal prints output to the terminal, you can redirect it into a ﬁle, or send it as input to another program. To place it in a ﬁle, you use > or >>. The ﬁrst will overwrite an existing ﬁle, the second will append to it (add to the end of the existing ﬁle). You can also send the contents of a ﬁle as input to a program, using <. > ls > fil > tr ’a-z’ ’A-Z’ < fil Here, the list of ﬁles are saved, and then sent to tr which will translate all (English) characters to uppercase, and print the result to the terminal. To avoid using a ﬁle, you can also send data directly from one program to another, a pipe or pipeline. > ls | tr ’a-z’ ’A-Z’ 36 7.1 More about the command-line interface Terms standard output data that a program prints (to the terminal, unless redi- rected elsewhere). A.k.a “stdout”. T standard input where the program reads data. A.k.a. “stdin”. standard error used to print errors, so that they can be shown even if stdout has been redirected. A.k.a. “stderr”. pipeline, pipe what binds two program together, and the name of the character | which is used to do so.6 AF Pipelines are used to build more complex commands. Some examples: > find . -name "*.doc" -print0 | xargs -0 gzip -9 > cat *.txt | \ sed -e ’s/[^a-zA-Z ]/ /g’ | \ tr ’A-Z ’ ’a-z\n’ | \ grep ’[a-z]’ | \ sort -u | \ comm -23 - /usr/share/dict/words Note that the second example uses backslashes to place each program name on a separate line. Brieﬂy: 1. ﬁnd all Word documents, and compress them 2. Merge all text ﬁles, ﬁlter away non-letters, translate to lowercase let- ters with one word on each line, remove empty lines, sort and remove duplicates, look for words not found in a list of known words. Phew! DR In other words, a rudimentary spell check. (There are better special- ized programs to use.) Useful tools sed Automatically edit text, e.g. search-and-replace. (The name comes from stream editor.) awk More advanced text editing. In principle, sed works on a single line at a time, but awk on multiple lines. (Named after Aho, Weinberger, Kernighan, who wrote the program.) grep Search for text using regular expressions.7 (The name comes from global / regular expression / print, a sequence of instructions used in old text editors such as ed.) tr Translate or remove letters. Exchange letters found in one set for those found in another, or remove the letter (depending on what ar- guments are given). diff Compare text ﬁles line by line. 6 In other context, the character is called vertical bar. 7 Regular expressions (regexps) are a very powerful way of matching text; what wildcards want to be when they grow up. It is a tool that demands careful consideration—regular expressions can be immensely complex, and you can easily make a mistake with the more advanced regexp constructs. 37 Details 7.1.6 Alias and functions To give a short name for commands you use often, you can deﬁne an alias. > alias ll=’ls -laFrt’ T Here, every time you write ll, the shell will instead call ls -laFrt. The replacement is done before calling the command, so you can give further arguments, e.g. ll Public/. If your alias needs to give arguments after the end of the command line that calls it, you can instead make a bash function. Below,$* will be
replaced with the given arguments.8

AF
> lm () { ls -l $* | more; } Alias and functions are normally placed in one of bash’s conﬁguration ﬁles, usually .bashrc. The .bashrc created for new CSC accounts con- tains some examples. 7.1.7 Exporting environment variables Environment variables are used to communicate to programs what printer should be used, where libraries or other software are located, and so on. The system will set some variables when you log in, others can be set by you on the command line: > export variable=value (If only bash is to use the variable, no export is needed.) 7.1.8 Modules DR With the large number of applications available at KTH CSC, and unlike most computers found at home, we must also9 keep multiple versions installed of some programs. The most common ones are available in the standard environment, but to get access to others you may need to use so-called modules. This is done with the command > module add module_name where module_name is one of the (many) module listed by > module avail To learn which module (or modules) gives access to a particular comm- mand, use > whichmodule program To always use a module, you can either say > module initadd module_name or manually edit the ﬁle ~/.modules (read when you log in) to add mod- ule_name. module help gives more options. 8 You may want to investigate what "$@" is (including the quotes) rather than use this

example as-is.
9 In particular for the Solaris environment, which has been developed over several decades

38
7.2 AFS och Kerberos

7.2       AFS och Kerberos
Andrew File System is a distributed network ﬁle system. It can be used
from all computers that have an AFS client installed. Versions are available
for all standard operating systems. All U NIX home directories at KTH CSC

T
are stored on AFS.
AFS is organized in “cells”, for example nada.kth.se, pdc.kth.se and
andrew.cmu.edu (they are more or less equivalent to Internet domains).
Cells contain “volumes”; your home directory is one such cell. To see the
name of a volume, you use fs exa:

> cd
> pwd

AF
/afs/nada.kth.se/home/3/u1ak8b73
> fs exa
File . (868903664.1.1) contained in volume 868903664
Volume status for vid = 868903664 named home.3.u1ak8b73
Current disk quota is 200000
Current blocks used are 138294
The partition has 44513490 blocks available out of 746334433

As shown, the name of the home directory’s volume matches the path,
and is named home.3.u1ak8b73.

Security is handled by Kerberos, a network authentication protocol.
With Kerberos, you request a “ticket”, that grants access to a “service”,
for example access to AFS. Rather than being divided into cells, Kerberos
uses “realms”. In practice, there is little difference, except that realms
are written with uppercase letter. Thus, the AFS cell nada.kth.se requires
DR
tickets for the realm NADA . KTH . SE.
Usually, you don’t need to care about realms or cells; all details are
handled automatically. When you log in, you recieve “tokens” (a type of
tickets) which grant you access to your home directory. You don’t often
need to use the AFS and/or Kerberos applications directly, but you should
have a basic understanding of how they work, in particular, how the access      6.3.9
rights are set. (You use fs sa, see the section about access rights .)

7.2.1      Tickets

To get tickets, you use kauth.10 This gives you a TGT, Ticket-Granting
Ticket. The default settings for CSC systems, is that this ticket is forward-
able, and that you also recieve AFS tokens. These can also be explicitly
requested with afslog.11
To see your tickets, use klist. On Ubuntu and Solaris systems, klist
-Tf will also show your AFS tokens. On other systems, tokens can show
them.
If you need to access AFS volumes in other cells, or for some other          10.3.4
reason need a ticket in another realm, see the documentation, or ask
Systemgruppen . Some useful commands are: kauth/kinit, klist,
afslog/aklog, tokens, kpagsh.
There are also graphical applications to handle tickets, e.g. Ticket
Viewer on Mac OS X (found under /System/Library/CoreServices).

10 On   some systems, kinit is used instead
11 Or   aklog.

39
Details

T
7.2.2      Quota
All home directories (or other AFS volumes) have a quota, that is, a limit
to how much space can be used. To see the quota, the command fs

AF
listquota is used (fs lq for short):
> fs lq directory

The number of subdirectories does not matter. All directories in a vol-
ume share the available space. On the other hand, some “subdirectories”
may actually be mountpoints for AFS volumes, with their own quota. For
example, ~/.OldFiles is a backup copy of your home directory from the
day before; its quota does not affect that of the home directory.

7.3       Special access rights
6.3.9
Most things about access rights is mentioned in the section about access
rights .
You may also want to know that some services at CSC (e.g. web servers)
may use access ﬁles as special “users.” Thus, if you wish to limit access
to a particular directory so that only the web server can access it, you
can give access to the user wwwservice rather than system:anyuser. This
DR
should not be considered secure! Since all users who have a webpage
can ask the server to read the ﬁles, it is at most security by obscurity
http://en.wikipedia.org/wiki/Security_by_obscurity .

7.3.1      Access groups
The pts command is used to view and create access groups. All AFS
users can create personal groups, the groups’ owner is part of its name:
«user»:«group». You can use this to create a group containing your
colleagues, lab partners, etc., and then add or remove users in the group
rather than change the access lists for several different directories.

> pts creategroup owner:group

creates a group. Users are added or removed with pts adduser or pts
removeuser, respectively. See the ﬁle README-AFS in your home directory
for further information.

7.3.2      Backups—OldFiles
All home directories (and most other volumes) are backed up daily. The
latest backup is available in the directory .OldFiles in your home direc-
tory.12 There is also a symbolic link, without the leading period, so that
the backups will be easier to ﬁnd, without causing a command such as
12 The   only backup you have access to, is the one from the day before. But Systemgruppen
10.3.4 saves backups in a rolling schedule, so that daily, weeky, monthly etc. backups are
available. With luck, a lost ﬁle may be available, but you should try to narrow down a speciﬁc
time period, to make it as easy as possible to ﬁnd it!

40
7.3 Special access rights

> find * -name "brev.doc"

to look through OldFiles.
The disadvantage of this, is that commands that don’t understand AFS

T
may give faulty (or unnecessary) results. If you search your entire home
directory (find . rather than find * above), you will often get two hits—
one being the superﬂous .OldFiles/same/path/as/the/other/result.
If you for some reason want to make a copy of your entire home directory,
you may want to make sure that an extra copy is not created.
Some applications that show your disk usage, will also make mistakes.
Finder (Mac OS X) can under some circumstances believe your home di-
rectory to use no space at all, while Disk Usage Analyzer (Baobab) believes
that OldFiles uses half the space available

AF
Technically, backups are kept in special AFS volumes, named
DR
«volume».backup. The example above used the volume home.3.u1ak8b73.
Its backup would be home.3.u1ak8b73.backup, and the OldFiles direc-
tory could be (re)created by

> fs mkm ~/.OldFiles home.3.u1ak8b73.backup
> ln -s .OldFiles ~/OldFiles

7.3.3    Shared directories
To create a directory where you and your lab partners can save common
ﬁles, create a directory in either user’s home directory and conﬁgure the
access rights so that everyone can access it. Then create links to the
directory.
Although the directory can use any name, and be placed in a subdirec-
tory, it is often best to name it after the course, and place it in the home
directory.13
Note that subdirectories to the course directory should be created after
the access rights have been changed. Otherwise, the access rights won’t
be inherited.
The command course labdir makes this easy to do. See example 2
below.

Example alice wants to work with bob and charlie in the course “C pro-
gramming”. She creates the directory and changes the access rights (write
here equals rlidwk).
13 Otherwise all users must have access to all directories between the home directory and

the course directory—or they won’t ﬁnd it.

41
Details

alice:~> mkdir ~/cprog09
alice:~> fs sa ~/cprog09 bob rlidwk
alice:~> fs sa ~/cprog09 charlie write

T
Then bob and charlie can create symbolic links to the directory

bob:~> ln -s ~alice/cprog09 ~/cprog09

charlie:~> ln -s ~alice/cprog09 ~/cprog09

11.3
Example 2 To do the same with course labdir                  , all three users can
enter almost the same command:

AF
alice:~> course labdir cprog09 bob charlie
bob:~> course labdir cprog09 alice charlie
charlie:~> course labdir cprog09 bob alice

In other words, each user enters the names of the other two. (The
directory is placed in the home of the user who ﬁrst uses the command.)
The directory will be set up precisely as in the ﬁrst example, except that
all will be given full access rights.

7.3.4       Different access rights in the same directory
Some ﬁles in your home directory must be read as you log in, before au-
thentication has been done. Others may contain secret information (pass-
words, email addresses). Access rights in AFS are set on a directory level,
so what can you do?
The solution is to give list access rights (but not read) to sys-
tem:anyuser, and then create a subdirectory that is publically readable,
where non-secret ﬁles are placed. For each ﬁle that should be public, you
DR
then create a symbolic link pointing to the ﬁle in the subdirectory. Pro-
grams can then access the public ﬁles through symlinks in the non-public
directory.
How to set this up:
>   cd                                   go to the home directory
>   mkdir Public                         create subdirectory
>   fs setacl Public system:anyuser read make it public
>   mv .bashrc .bash_profile Public      move files there
>   ln -s Public/.bashrc                 create links
>   ln -s Public/.bash_profile

New CSC accounts are set up this way, see Restore default settings
10.5.4 for more information.

7.4       Homepage (public_html)
To create a homepage, you place a ﬁle called index.html in the directory
public_html. The ﬁle should contain HTML code.14
§                                                                        ¤
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>Minimal</title></head>
<body>
<p>This is a minimal page with HTML code</p>
<p>Here’s a link: <a href="http://www.kth.se">KTH</a>.</p>
</body></html>
¦                                                                                     ¥
14 Instructions
for creating HTML are available online, for example w3schools
http://www.w3schools.com/ .
You can also look at the code of webpages. Many (e.g. KTH’s homepage) are however
automatically generated, which does not always give readable HTML code.

42
7.5 Remote access (ssh)

The homepage can be reached at http://www.csc.kth.se/
~«username»/.
Note that the name index.html is given special treatment. The name
http://.../directory/ is interpreted as requesting the ﬁle index.html
in that directory. // TODO :// Fast endast på www.student; www.nada och

T
www.csc tolkar det som ett fel. Other ﬁlenames must be explicitly entered.

Some settings can be altered. For example, if you wish to use the name
image.jpg in the same way as index.html, you can (if you know how
the web server Apache works) change this. Such changes should only be
made by those who know the consequences! Making a mistake may
affect not only other users, but other functions at CSC.

AF
7.5     Remote access (ssh)
To access CSC systems from home, you can use some form of remote
access. There are also tools for moving ﬁles, either to or from CSC. Of
course you can also move ﬁles using a USB memory stick, CD or similar,
but this requires physical access; that you are able to sit down at one of
CSC’s computers. This is not always possible—nor is it necessary.
To access a CSC computer remotely, you can use some form of SSH
(Secure SHell) or (for ﬁle transfer) SFTP or SCP (SSH File Transfer Protocol,
Secure Copy)15

7.5.1   Terminal access (SSH)

If you use Mac OS X, Linux or some other U NIX variant, the SSH based
commands are probably already installed. For Windows, there are multiple
free clients, the most common being PuTTY.16
When you log in, you do so from your local computer (client) to a remote
host (server). Although you can in principle do this to any CSC computer,
DR
you should use one of the computers reserved for this purpose

s-shell.csc.kth.se – a server running Solaris, the traditional CSC com-
puter environment, and also the OS used on webservers et al.

u-shell.csc.kth.se – a server with Ubuntu Linux, which is now used in
most computer rooms. (Note, this server will be installed during the
fall of 2010.)

When connecting to the remote host, you may be asked to conﬁrm its
“key ﬁngerprint”. Most programs save this, so you should not be asked
again the next time you log in (with that program, from that computer).
The key for the publically accessible servers at CSC are available on
Remote login at CSC
http://www.kth.se/dokumentation/it-support-csc/faq/fragor-och-svar-kring-fjarrinloggning-pa-csc

Ubuntu (Terminal)                     Mac OS X (Terminal.app)
15 The traditional Telnet or FTP programs can also be used, but only versions that are

Kerberized, i.e. support Kerberos authentication. SSH is recommended instead.
16 PuTTY      http://www.chiark.greenend.org.uk/~sgtatham/putty/           is common
enough to be the ﬁrst match on Google.

43
Details

7.5.2   File transfer (SFTP, SCP)
Most ﬁle managers in Linux recognize SFTP, so opening the “directory”
sftp://«user»@host.csc.kth.se/«path» will show a dialog asking for
your username and/or password. Then you can open another window for

T
your computer, and drag-and-drop ﬁles between the windows.

AF
Unfortunately, Mac OS X does not contain a graphical SFTP client. You
can use the command-line version, or download and install Cyberduck 17 .

For Windows, you can use WinSCP.
DR
7.5.3   X11 forwarding
One of the greatest advantages of SSH is automatic X11 Forwarding, i.e.
that applications running on the remote host are displayed on your local
computer. This requires that you run an X server on your computer, which
is available for U NIX and Mac OS X, but must be installed separately on
Windows.18
If an X server is running, you only need to start SSH with the option
-X. Note that its an uppercase letter, -x does something else.
With a slow network connection, many applications may be difﬁcult
to use, as all communication is done over the Internet. Applications
like Emacs, which basically only displays text, usually work well enough.
Other applications may allow you to turn off graphical effects. M ATLAB
can even be run in a command-line mode, using the options -nosplash
-nodesktop. To write the code, you can use e.g. Emacs.19 Showing plots
and other windows will work, albeit slowly.
17 Cyberduck   http://cyberduck.ch/
18 Cygwin/X    http://x.cygwin.com/   is free, but complicated to install.    Xming
http://www.straightrunning.com/XmingNotes/ is easier to use, but only older versions
are available for free.
19 Someone used to Emacs can even run M ATLAB as a shell within Emacs.          M-x
matlab-shell starts M ATLAB, and C-c C-s saves and evalutates the ﬁle.

44
7.5 Remote access (ssh)

T
7.5.4      Heavy processing
Most CSC students only use the computers in the computer rooms, and
possibly the login servers for remote access. None of these are appropriate

AF
to run heavy, long-running computations. First, since processes making
heavy use of resources (CPU time, memory, bandwidth) can create prob-
lems for other users’ programs. But also since (with computers in the
computer rooms), you do not have any control over the computer. If a
local user reboots the computer, the calculations may be lost.
For heavy computing applications, CSC runs dedicated computation
servers, more or less powerful computers located in the server rooms.
These are not publically available, however. To (as a student) gain access
to them, you must talk to your course leader.
Those with long-running jobs should also look into how to best run
the jobs. For example, you should take measures to allow your program
to keep Kerberos tickets when you log out from the machine. You will
probably also want to look at programs such as screen and kpagsh, and
learn how to run M ATLAB without its GUI.

7.5.5      Kerberos remote access
To avoid having to type your password each time you log in, you can install
DR
Kerberos on your home computer. The beneﬁts are:
• The KDC20 can conﬁrm both your and the server’s identity.
• Single sign on – you give your password on one machine, to get your
initial tickets. Other computers never need to see your password, and
thus can’t reveal it.
• The forwarded tickets have a limited lifetime. Stolen keys can be
revoked, rendering them useless.
Most modern SSH implementations (including SCP and SFTP) have
GSSAPI21 support for Kerberos. As do email clients and web readers.
SSH in particular, can use GSSAPI for
Veriﬁcation
Rather than conﬁrming a host key, you can use Kerberos to conﬁrm
the remote host’s encryption key.
Authentication
If you have current Kerberos tickets, they are used to conﬁrm your
identity. You don’t need to give your password to log in.
Forwarded keys
The keys you acquire can be made forwardable. Then they are sent
to the remote host, and used to e.g. get AFS tokens.
7.5.2
Using a ﬁle manager with builtin SFTP support , and the ability to
create launchers that automatically start SSH , once you have kauth:ed,       3.2.1
20 Key   Distribution Center, the Kerberos server
21 Generic   Security Services Application Program Interface

45
Details

you can open multiple new terminals and ﬁle manager windows to a CSC
host, all without re-typing your password.
(You should however use kdestroy before turning off or leaving your
computer; rebooting the computer in failsafe mode may allow others to
gain access to your tickets.)

T
For more information regarding how to install and conﬁgure Kerberos,
see Systemgruppen’s webpages: Conﬁguring Kerberos on a U NIX/Linux
host http://www.kth.se/dokumentation/it-support-csc/environment/solaris/instructions/kerberosconfi

AF
DR

46
Emacs

8     Emacs
When writing a text ﬁle occasionally, there are text editors easier to use
than Emacs. On the other hand, if you will be writing a lot of plain
text, as most programmers will, it is useful to learn one of the more ad-

T
vanced editors, developed for programming. Emacs is one of the oldest
and most common ones found in a U NIX environment. It has also been
recommended for decades at KTH CSC’s courses.
Emacs has been around since the late ’70s, and is so common that
other applications (e.g. command-line shells) often use its more common
keyboard shortcuts. Emacs’ strength is its vast function library, with “help
functions” that are in some cases practically applications of their own.
The disadvantage is that the sheer number of settings make it difﬁ-

AF
cult to use. In the beginning, you are probably best off using the menus,
e.g. File → Open File. . . to open ﬁles. But Emacs is built to be used with
shortcuts—only a small part of the functionality can be found in menus.
A brief list is found at the end of this section; a more extensive one at the
end of this document.
To run Emacs without the GUI (for example, when logged in remotely),
you can use emacs -nw. But you will need to know the shortcuts, to be                            3.6
able to use it! For some alternative applications, see here .

Emacs uses some old terms, no longer used the same way in other
context. A window is called a frame, a ﬁle is a buffer, and due to the
number of keyboard shortcuts, you will often need to use two keyboard
combinations rather than one. These are therefore written as C-x C-o
rather than Ctrl-X Ctrl-O.1
DR

Emacs will often have multiple ways to perform the same task. To open
a ﬁle, you may:

1. Choose File → Open File. . . , for a graphical dialog where you can select
the ﬁle. Visit New File can be used to create a new ﬁle: “opening” a ﬁle
that does not exist will create the ﬁle when you save the buffer.
1 This document normally use the latter, but in this section we will use the notation found

in Emacs’ documentation.

47
Emacs

2. Choose the equivalent button in the tool bar, below the menus:

T
3. Use the shortcut C-x C-f and enter the name in Emacs’ minibuffer
(the row at the bottom). Just like on the command-line, you can use
«tab» for autocompletion.

4. Use M-x and call the function ﬁnd-ﬁle by name. Press M-x, enter
find-file («tab» will work), and press «return».

Functions found in the menus will show the shortcut next to the menu

AF
item, and give a brief description if you hover the mouse over it.
Mistyping one of the often complicated keyboard sequences2 , you can
abort it by pressing C-g a few times.

8.1       Text editing, cut-and-paste
The cursor, a ﬂashing black rectangle, will show where the insertion point
is, the place where text will be entered. To move it, the normal arrow keys
and «Home», «End» will work. But to avoid moving your hands around the
keyboard, there are also shortcuts available for this

C-a Move to the beginning of the line

C-e Move to the end of the line

Text is deleted backwards with «backspace», and forwards with «delete»
or C-d. You can also use

C-k Delete the rest of the line (k for kill)
DR
M-d Delete the next word

C-w Kill marked region (cut)

M-w Copy region

C-y Paste (S-«insert» will also work)

C-_ Undo.

Text is marked by pressing C-«space» to start a mark, move the
marker, and then cut/copy using C-w or M-w. Pasting is then done with
C-y (for “yank”).3
2.1      You can also use the mouse to mark text. Emacs uses the same copy
mechanism as mid-clicking    the mouse. So, if you have marked text
using the primary mouse button, you can paste it in Emacs with C-y.

8.2       Searching
To search for a word, place the marker where you wish to start, then press
C-s. Type the word you are looking for, and Emacs will move to it (and
mark other places where the word can be found). To ﬁnd the next match,
press C-s again. To exit the search, press «return».4 To return to the
start of the search, press C-g.
2 The minibuffer will, after a few seconds, show what you pressed
3 Allcuts (or “kills”, that have been “yanked” from the text) are placed in a “kill ring”. After
pasting, you can use M-y to access previous kills.
4 To search for a linebreak, use C-j in the search ﬁeld.

48
8.3 Handling multiple ﬁles

The search will “remember” what you looked for last. Having used it
before, you can press C-s C-s to once again search for the same word.
C-r searches backwards, otherwise works the same.
“Search-and-replace” can be found at Edit → Replace → Replace String. . . ,
or M-%. Emacs will prompt whether or not to replace each match. y re-

T
places, n jumps to the next and ! replaces all (remaining) matches.

8.3    Handling multiple ﬁles
Emacs can keep several ﬁles active, each in their own buffer. You can
select which one to use from the Buffers menu, or the more common C-x b.
You can also split Emacs into multiple subwindows (“frames”). File →
Split Window or C-x 2 splits horizontally, C-x 3 vertically and C-x 1 re-

AF
moves all splits in the current window. A new window (frame) is created
by File → New Frame, C-x 5 2.

If the current ﬁle has not been saved for a few minutes, Emacs will save
a copy with # added to the name, giving #hello.c# for hello.c. If you
accidentally log out without saving, that ﬁle will remain and can be used
to re-create the ﬁle.
Having edited an existing ﬁle, you will also see a “tilde ﬁle”, a ﬁle ending
in ∼ (hello.c~). Regardless of how many times the ﬁle is saved, the ∼ ﬁle
is a copy of what was there before you opened the ﬁle.

8.4    Modes
Emacs will change its behavior depending on what type of ﬁle is edited.
This is controlled by various modes. Normally determined from ﬁle exten-
tions recognized by Emacs, you can also manually set the current mode.
What is changed varies, but normally some menus are added, some keys
or shortcuts are altered, and syntax highlighting is used to color some
words in the text. The current mode is shown in the mode line.
DR
Syntax highlighting (font-lock-mode) on and off.
To manually select the mode, you use e.g. M-x matlab-mode.

8.5    Settings
Emacs settings are saved in ~/.emacs. Previously, you had to edit this
ﬁle manually, and many online help pages still give instructions for how
to do so. (The new way is only 15 years old. . . ) You can browse the setting
groups by choosing Options → Customize Emacs → Top-level Customize Groups.
Alternately, to change a speciﬁc setting, choose (from that menu) Spe-
ciﬁc Option. . . , or use M-x customize-option, and enter the name of the
variable controlled by that setting. The variables have the same name as
the settings, but with lowercase letters and dashes rather than space. So,
Line Number Mode is controlled by line-number-mode.
Some of the most common options are
Global Font Lock Mode Syntax highlighting, the use of colors to make
program code more readable. Very convenient, when you are used
to it. New Emacs versions have it enabled by default, previously you
had to enable it underOptions → Syntax Highlighting.

49
Emacs

Transient Mark Mode Highlight the currently marked region (using a
beige background). Makes it easier to see what cut/copy commands
will affect.
Show Paren Mode Highlights matching parenthesis (or brackets, braces,

T
etc.). Also found as Options → Paren Match Highlighting.

CUA Mode Conﬁguring M-x cua-mode, or the equivalent under Options,
makes Emacs use the shortcuts speciﬁed by the Common User Access
guidelines. In practice, Emacs will then use Ctrl-X, Ctrl-C and
Ctrl-V to cut, copy and paste. In most cases, normal shortcuts like
C-x C-s will still work as usual (you can’t cut if there is no active
region), and you can also use Shift, as in S-C-x C-s, to access the
normal shortcuts.

AF
8.6   Help
Emacs’ builtin documentation is very extensive. The menu Help contains
among other documentation, the Emacs tutorial, which will give a basic in-
troduction to the application. Help on shortcuts, modes etc., are available
from Help → Describe. If you choose Describe Key before using a shortcut
or clicking a menu item, no action is taken. Rather, the documentation
pertaining to the action is shown. List Key Bindings will show a (massive!)
list of what shortcuts are available.

8.7   Alternate applications
There are some alternatives to Emacs, that you should know about.

XEmacs After almost 35 years of development, many versions of Emacs
exist, apart from the normal one (which is formally known as GNU
Emacs). One of the most common is XEmacs. Brieﬂy, the differences
are mostly noticable only for those used to either version; functional-
DR
ity introduced in either tends to show up in the other.

No X? If, for some reason, you don’t have access to a window environ-
ment (mostly when running a computer in single user mode for sys-
tem maintenance), Emacs may not be available either. “Replacement”
applications are nano or pico under Linux or mg under Solaris.

50
Programming

9     Programming
Programming is addressed by KTH CSC’s courses. There you will learn
what a program is, and how to write the code that they are created from.
Since this is done differently depending on what programming language is

T
used1 (with different languages used by different courses), this document
will not discuss those details. We will only mention what is needed to
actually run the programs you create.
Although some courses may teach you how to use applications that
perform parts of the work for you, it is also good to know how to manage
withouth that help. If you have only ever used a button labled “Run” in
an IDE (Integrated Devolopment Environment), you will ﬁnd it harder to see
the difference between compiling a program and executing it. If, on the

AF
other hand, you have used java and javac separately, you will understand
perfecly well what happens when the button is pressed.
The below summaries are not intended as an explanation. It will be dif-
ﬁcult to follow the text without having previously understood the concepts.

9.1     Java
A Java program is written in one (or several) ﬁles with the extention
.java. It is an object oriented language; every ﬁle may contain one or
more classes. Normally, one ﬁle is used for every class in larger projects,
but if the classes are small and few, you can place them in the same ﬁle.2
Each ﬁle is compiled using the javac program into binary code,
one (or several) class ﬁles. You go from «something».java (text) to
«something».class (binary).
Since Java programs are platform-independent,3 the program java is
used to run the program. There are also applets, programs that run in-
side a web browser or using the program appletviewer.4 Technically, the
DR
program is said to be interpreted by a virtual machine. Concepts like just-
in-time compilation does make things a bit more complicated though.

Examples

> javac HelloWorld.java
> ls HelloWorld.*
HelloWorld.class        HelloWorld.java
> java HelloWorld

For an applet, you will in addition to the class ﬁle, also need an HTML
ﬁle with an <applet> tag5 . It can be shown in a web browser, or by

> appletviewer HelloWorld.html

1 Learning multiple programming languages, you will soon see the common aspects and

expressions. All if -clause works similarly regardless of whether the language is C, Python
or M ATLAB. But in the beginning, it’s difﬁcult to see the forest for the trees, i.e. distinguish
between syntax and concepts.
2 There are rules for when this can or cannot be done.
3 The same binary code can be run on different computer architectures or operating sys-

tems.
4 Although Java programs can be written so they can run either as a separate program, or

as an applet, this is quite difﬁcult. It is better to ﬁrst learn both ways of program development,
and later look at how they can be combined.
5 Using a short form of the element, <applet [...]                   /> rather than <applet
[...]></applet> is not recommended; not all applet viewers understand it. Also, using
an applet element in the HTML ﬁle, while deprecated, is more supported than the newer
object

51
Programming

9.1.1    Integrated Development Environment, IDE (Eclipse)

There are several IDEs for Java. An IDE will, apart from a text editor,
contain tools for organizing the ﬁles that constitute the program, to com-
pile and run the code, a debugger, etc. Eclipse also contains tools for

T
constructing GUIs.
Eclipse is found under Applications → Programming.

9.2     Python
Python is a programming language built to encourage readability. Unlike
other programming languages, the indentation (left margin) is a part of the
language, not something that is only adjusted to make the code readable.
Python is build to support many different paradigms,6 including object

AF
orientation and (to a small extent) functional programming. Version 3
of Python is not backwards compatible with version 2, although some of
the newer concepts have been retroactively introduced in that version (cf.
“backporting”).
Both versions are installed, as python2 (the default) and python3:

> python2
Python 2.6.5 [...]
>>> print round(1.5), " :: ", round(2.5)
2.0 :: 3.0
>>> exit()

> python3
Python 3.1.2 [...]
>>> print(round(1.5), " :: ", round(2.5))
2 :: 2
>>> exit()
DR
9.2.1    IDE (Idle)

Python is distributed along with a fairly rudimentary development envi-
ronment, I DLE. Normally run with one window for text editing, and one for
input/output to the program.
Idle is found under Applications → Programming.
5.1.2
To run Idle on a thin client on Solaris , you may need the command-
line option -n.

9.3     M ATLAB
M ATLAB (Matrix Laboratory) is used for mathematical computations based
upon numerical (rather than symbolic) methods. M ATLAB is built to use
matrices of numbers, and matrix manipulations are a basic part of the
language. The program is often used to visualize data, with 2D and 3D
graphs.
M ATLAB has its own built-in IDE, but can also be run without it.7 The
environment works analogously on all platforms, but if you are used to
for example Windows, you can choose to use those shortcuts under U NIX
as well, where “Emacs-style” shortcuts are the default. The setting is un-
der File → Preferences. . . → Keyboard, and are called Command Window key
bindings and Editor/Debugger key bindings.
6 Programming paradigms differ in how concepts and abstractions are expressed, and how

you organize and structure programs. Different problems are more or less suited to a partic-
ular paradigm.
7 Not commonly used on introductory courses, but useful when heavier processing

7.5.4 is required.

52
9.3 M ATLAB

Also note that M ATLAB’s command window can be used as a real termi-
nal. ls and a few other commands are builtin functions in M ATLAB, but
you can also call system commands as !«command».
M ATLAB is found under Applications → Programming.

T
9.3.1   Octave
AF
GNU Octave, like M ATLAB, is made for numerical calculations. Its lan-
guage is highly inspired by M ATLAB’s, and with some experience it is rela-
tively easy to write programs that can be run in either Octave or M ATLAB.
Doing this is not recommended for the non-experienced programmer; the
differences are more likely to be confusing.
DR
(GNU) Octave is found under Applications → Programming, but you can
also run it as octave in a terminal window. (The shortcut will otherwise
start a new terminal.) To write the code, use your preferred text editor.

53
Documentation and help

10        Documentation and help
No documentation can cover everything. To ﬁnd information about com-
puter systems and applications, it is therefore more important to learn
how to ﬁnd documentation, rather than how to use a particular source

T
of information. Much can be found online, but in order to understand it,
you need some basics. Partly to know what terms to use to limit your
search, but also to understand how to read documentation. Documenta-
tion is usually indented as a work of reference, not a manual or primer.
Compare with mathematics: an engineer who need the differentiate of arc-
sine does not wish to learn how to differentiate a function, nor to deduce
the trigonometric functions. He already knows all that. He wants the
formula

AF
d                1
arcsin x = √
dx              1 − x2

and will thus use a reference manual rather than a mathematical textbook.
Man pages (or other documentation) are likewise intended for those who
know the basics of what they want to do, but needs to look up the details.
If you know that ls lists ﬁles, you may look up the option -t, to sort the
listing after the ﬁles’ modiﬁcation date.
When you are looking for speciﬁc details, you need to know how doc-
umentation is organized. Skimming the text to ﬁnd what you need, can
then be done quickly.

10.1        Man pages (man, info)
Man pages (short for “manual pages”) are the quickest way to ﬁnd infor-
mation on commands and application settings. To show a man page in the
terminal, you use
DR
> man term

The page1 contains a brief sum-
mary of what the command does, MV(1)                    User Commands        MV(1)
then a synopsis of how to use the NAME
command. Then a more extensive                 mv - move (rename) files
description, which will also tell you SYNOPSIS
what the arguments are.                        mv [-fi] source dest
mv [-fiu] source... directory
In this case, the synopsis tells
that the most common way to call DESCRIPTION
[...]
the command is as mv, possibly
using either the -f or the -i op-             Figure 2: man page for mv
tion, but deﬁnitely with something
called “source” and something called “dest”, but both should be replaced
with something else in the actual call.
The second way to call mv also allows the option -u. Since there is an
ellipsis (“...”) after “source”, you can repeat it (give multiple ﬁles). The
last argument should now be “directory”.
The heading description will tell you what the arguments (“source”, etc.)
actually are, but with some experience, the synopsis alone will tell you that
the ﬁrst case is used to rename a ﬁle, and the second to move several ﬁles
to a directory. The options are also explained; in this case, -i to prompt
before overwriting a ﬁle, and -f to never prompt.
The notation may vary slightly. Either of “SOURCE”, “source” or
“<source>” could mark the text that should be replaced. But most man
pages use the same conventions.
1 The   actual page is slightly different, with more options.

54
10.2 Online support

Tips regarding related commands are usually found under the heading
see also near the end of the man page. The pages are grouped into cate-
gories. “See mkdir(1)” refers to the mkdir that is a command, not mkdir(2),
a system call in the programming language C.
The apropos command can also be used for pointers to commands:

T
> apropos rename
mv (1)          - move (rename) files
pts_rename (1) - Changes the name of a Protection Database
entry
rename (1)      - renames multiple files
vos_rename (1) - Renames a volume

AF
Man pages can be found online, both on CSC’s web pages and else-
where. But details such as options may vary between the different versions
used in different operating systems,2 so looking at the local man pages is
preferred.

The Info system is built somewhat differently. They are more based
upon hyperlinked3 documentation than man pages. Info documents are
mostly used to document GNU software. They can be read online, in
Emacs, or using the command info.

10.2       Online support
Speciﬁcally for Ubuntu, Canonical (the creators of Ubuntu) have
links to free community support available from their homepage
DR
http://help.ubuntu.com . There is also an online forum http://ubuntuforums.org/ .
For other systems, there are many FAQs and web sites that can answer
questions. The links in this document to various topics at Wikipedia pro-
vide a good starting point. They usually provide information about who
the developers are, and links to their websites.

10.3       Personal assistance, tutors
10.3.1     Course assistants (Swe. handledning)

For questions regarding any form of course-related material—homework,
assignments, laboratory work, etc—you should always ask your instruc-
tors, lab assistants and course leader. They are familiar with the speciﬁc
requirements, literature, relevant theory, and so on. Some courses have
scheduled hours for questions, others may reserve time during the lectures
or lessons. Check your course homepage for details.

10.3.2     Sima Manager

Sima Manager is an application used during computer labs to queue for
help with (or examination of) exercises. Many courses use it. You will ﬁnd
it under Applications → CSC → Sima Manager

2 Such as the different Solaris and Linux platforms at CSC.
3 “Hypertext”is text containing “hyperlinks” to connect it to other texts. It allows non-linear
reading, you can jump back and forth in the text. Web pages, based on the protocol HTTP,
HyperText Transfer Protocol is one example.

55
Documentation and help

T
Start the program, select the correct course, and Queue to add yourself
to the queue. If you are using a laptop, make sure to enter your location
in the comment ﬁeld (kommentar).

AF
10.3.3 Allmänhandledning, the general assistant
A general terminal room assistant (Swe. allmänhandledare) is available
twice daily, to offer help regarding any programming or computer prob-
lem. Note that questions speciﬁc to a particular course can generally not
be answered, since the assistants can’t be familiar with the details of ev-
ery course. On the other hand, they do have experience of working on
many different courses, and can often give a qualiﬁed guess as to what the
requirements are.
There is never more than a single assistant for each shift; if one problem
takes a long time to answer, you may have to wait for some time. The
assistant is always on the 4th ﬂoor. To get in contact with them, use Sima
(see above).
The homepage for the general assistant http://www.nada.kth.se/handledning/
has a schedule, which is always kept up-to-date, and also a FAQ.

10.3.4 Systemgruppen, the KTH CSC Systems Group
DR
CSC’s computers are administered by Systemgruppen, the KTH CSC Sys-
tems Group. Problems with the computers should be reported to them, at
system@csc.kth.se.
While not able to answer course-related questions, they may
be able to help with other computer questions.           Their help desk,
Delﬁ, is open all weekdays, and mail to the above address is han-
dled continously during normal ofﬁce hours.          See their homepage
http://www.kth.se/csc/it-support-csc for opening hours.

10.3.5    Other computer support
KTH has a page with links to the different computer support groups
http://www.kth.se/student/support?l=en_UK .

10.4     Speciﬁc problems – FAQ4

7.3.2   Accidentally deleted ﬁle
See backups , maybe it’s still in OldFiles?

Empty ﬁles
7.2.2      If your account is full, perhaps an application was unable to save a
previously open ﬁle? See quota .

“Weird” problems with Firefox
May also be caused by a full quota. Firefox will often behave strangely
if it can’t save all settings. Sometimes the SSL settings are corrupted,
and you cannot open any secure website (e.g. My pages at KTH . SE).
4 Frequently   Asked Questions

56
10.4 Speciﬁc problems—FAQ

“Over quota” error message
You have exceeded your quota. To see what is taking up the space,        7.2.2
use Disk Usage Analyzer (Baobab). See quota and the example with
Baobab .                                                                  3.2.1

T
• Try clearing away unnecessary ﬁles.
• Archive and compress ﬁles you rarely need. Ubuntu’s Archive
Manager is called file-roller, and can be run from a terminal
or by Alt-F2.
• If you require more space for course-related ﬁle, contact CSC’s
computer support, or your course leader.

AF
My new password doesn’t work
Did you change the correct password? There are many different
computer accounts used at KTH, and most of them use the same
username. To use CSC’s computer systems, you need a CSC com-
puter account. This account is not the same one as the central
KTH.SE account used at My Pages.
Email to the CSC account («user»@csc.kth.se) is usually forwarded
to «user»@kth.se. This is a setting you can change yourself (with
chpobox), but it’s best to forward one account to the other, so that
automatically generated messages are not overlooked.

Can’t log in
Wrong password? As stated, there are many different accounts; they
are easily confused. Or, perhaps it’s something as simple as Caps         3.1.1
Lock? Try using a different computer, or failsafe login .
If you can log in using a different computer, please report the one you
were unable to use to computer support.
DR
10.5.4
If the failsafe login works, you can restore your settings   .

Slow computer
One or more process may be overtaxing the CPU or memory of the            6.3.11
computer. See process management .
If another user’s processes are causing problems, contact computer
support. Whether it’s ignorance or malice, the problem should be
addressed!

Can’t save/read some ﬁles                                                     7.2.1
If you have been logged in for more than 10 hours, your Kerberos
tickets may have expired. Run kauth in a terminal.

Can’t remove USB memory                                                       3.7
If ejecting a USB memory     gives the message

another program is using that directory. Perhaps another terminal is
open, where that is the working directory?

57
Documentation and help

10.5      If you have an old CSC account
For those given a new computer account at CSC, everything should “just
work,” at least until you start to change your settings. But for those who
for some reason have an account created several years ago,5 there are

T
some things that might have to be changed.
For details on how these problems are to be solved, contact CSC’s com-
puter support.

10.5.1     Strange username
Until around the year 2000, when the department was still called
Nada6 the usernames were matched the form «group»«year»-abc eller
«group»«year»_abc, for example f99_aan for Alice Andersson. A few years

AF
thereafter, “u1 names” were used, such as u1ak8b73. In other words,
the unique identiﬁer used in the central KTH database. Today, the same
username is used as for your central KTH.SE account (“KTH account”). 7
For those who request it, old computer account can be renamed to the
same username as the KTH.SE account.

10.5.2     “Wrong” shell (tcsh or bash)
During 2008, the default shell was changed from tcsh to bash.8 For those
who have not chosen a speciﬁc shell based on a particular capability, the
differences are slight. It probably doesn’t matter which shell you are using.
Most of this document is valid in both tcsh and bash.
If you wish, you can change your shell using chsh (change shell).

10.5.3     Old settings
Old settings can cause mysterious problems. If you have previously had
an account at the Electrical Engineering department, you may not be able
DR
to log in since you have a .k5login ﬁle pointing to an account that no
longer exists. You may get strange error messages, caused by attempts to
start a Zephyr service that was removed in 2006.
Many still use the old window manager CDE on the Solaris systems,
even though the newer Java Desktop both looks and feels more modern.9
Settings are often (but not exclusively) stored in ﬁles called .«some-
thing»rc (for run commands). For example, .bashrc for bash.
The most important settings can be restored, see below.

10.5.4     Restore default settings
// TODO :// Vad av gnome-cleanup, local-ﬁxinit etc ska ﬁnnas under Ubuntu?
Vad ska rekommenderas?

5 For example, you may have been registered for a CSC course some years before. Such

accounts have typically been de-activated, but as long as the ﬁles remain, all old settings are
still used when the account is re-activated.
6 Numerisk analys och Datalogi, Swedish for Numerical analysis and Computer science.
7 Actually, the u1xxx string is your “KTH id”, but just about all KTH systems can now use

your username instead.
8 The names come from history, traditions and a few puns. tcsh = TENEX C Shell, the

successor to a shell using a syntax similar to the C programming language, inspired by an
old operating system. bash = Bourne Again Shell, successor to the classic Bourne Shell, sh,
created by Stephen Bourne.
9 Others deliberately stay with CDE, since if it ain’t broke, don’t ﬁx it.

58
Course administration

11     Course administration
11.1    My Pages
Course administration, including registration and registering for exams,

T
is done on My Pages, http://www.kth.se/student/minasidor. For more
information, see the web page.

11.2    rapp
Rapp is a system used internally at CSC, for course administration. Re-
sults for lab exercises, exams and similar are stored in rapp, and you can
log in to see your reported results. Documentation is found on the web-
page, http://rapp.nada.kth.se.

AF
11.3 course
The course command is used to recieve messages from the course leader,       7.1.8
and also automatically recieve any modules     necessary for the course.
(Provided your course leader has added them to the course module.)
Usage:

> course join numpp10
> course leave numpp10         ### after the course
> course list                         ### list all my courses

The command also has some utilities for e.g. sharing computer ﬁles
(lab work and such) with others:

> course labdir numpp10 alice bob charlie

11.4    res
DR
Res is an older system, used for many years for CSC’s internal admin-
istration. Largely replaced by rapp. Res is command-line based, and to
use it you need to log in to a Solaris machine. To register for the course
numpp10, you could do so:

csc-ubuntu:~> ssh s-shell
s-shell:~> res checkin numpp10
[...]

s-shell:~> res show numpp10

(res show will only work after newly registered checkins have been ver-
iﬁed by a course leader or assistant.)

59
60
DR
AF
T
T
AF  Appendix
DR
Some terms

A    Some terms
execute Running a program. An application or command typically con-
sists of one or more programs. Slightly simpliﬁed, a program consists
of a series of instructions, carried out in a speciﬁc order.

T
client, server When a computer or a program performs services using a
different computer (or program), the requestor is called a “client”,
and the provider is called “server” or “host.” For example, an email
program is a client to a server that handles the mail.
A “server” can also be a computer (usually a powerful one), that is
not used locally, but rather accessed remotely.
platform Depends on the context. Often a combination of the hardware

AF
and software used, e.g. operating system and CPU type of a computer.
For example, Mac OS X and Ubuntu Linux, or something more spe-
ciﬁc, such as Ubuntu running on an Intel x86-compatible CPU versus
Ubuntu on an UltraS PARC CPU.
workstation Traditionally, a powerful computer used for technical or sci-
entiﬁc applications, often networked with other computers. Today,
computers are powerful enough that the term is more likely to refer
to their use. A “media computer” used to play music and video ﬁles,
may well be more powerful than the “workstation” used to write its
software.

2   GUI (Graphical User Interface) Used both for the concept1 and when refer-
ring to a particular GUI, “The application’s GUI. . . .” See GUI .
characters The names of some common characters can be found in ap-
pendix B.
whitespace Characters that are not printed (that is space, tabs, line-
DR
breaks, etc) are collectively known as whitespace characters.
authenticate In security context: conﬁrm your identity. That is, demon-
strate that you really are the user you claim to be. (Usually, using a
a password or some other type of code.)
”foo?” Often used informally in documentation, as a placeholder for the
name of a variable or function that needs a name only so you can refer
to it. Called a metasyntactic variable. In mathematics, names such
as x, y etc. are often used, but in computer context, the names foo,
bar, baz are more common. The origins of the names are unclear, but
may have something to do with the American military abbreviation
FUBAR .

1 GUI   http://en.wikipedia.org/wiki/Graphical_user_interface

62
Common characters

B       Common characters

Char                     Name Example of use
#      Hash, pound sign. Often used to comment lines. In combi-

T
nation with an exclamation mark, #!, pronounced shebang,
see shellscript   7.1.3 .
$Dollar [sign]. Shellscript environmental variables. * Asterisk, star. Wildcard character 7.1.2 , used in pro- gramming, e.g. /* C-style comments */. / (Forward) Slash, solidus. Limit directories in paths 6.4.2 . \ Backslash, reverse solidus. “Escapes” (protects) characters AF on the command-line. Used for directories in MS Windows. @ At sign. Email addresses; symbol to represent symbolic links. Commercial invoices may use it to say e.g. “3 widgets @ 50¢ =$1.50”.
( )    Parenthesis, brackets (UK). Apart from their use in text and
mathematics, often used for function calls in programming:
printf("hello world\n").
[ ]    Square brackets, closed brackets. Optional arguments in
documentation. Chracter groups on the command-line.
Used in mathematics, e.g. for closed intervals,
[a, b] = {x ∈ R|a ≤ x ≤ b}
Note that Swedish often use the ISO notation, which uses
reverse square brackets rather than normal parenthesis:
]a, b[ (ISO) = (a, b) (US) = {x ∈ R|a < x < b}
{ }    Braces, curly brackets. Block limiter in many program-
ming languages; expands to groups on the command-line
(ls {alpha,beta,gamma}.txt). Sets in mathematics (see
DR
the above example).
< >    Less than, greater than. Used for redirection (connecting
program input/output to ﬁles or other programs) on the
command-line. Mathematical/logical relations. Often used
as angled brackets.
Angled brackets, chevrons. Enclose or highlight material.
Often confused with less than and greater than.
« »    Guillemets, angle quotes. Used to quote text. » should not
be confused with >> (double greater than), used for redirec-
tion.
^      Caret, hat; circumﬂex (accent). Used in programming, for
example exponentiation: (5^3 = 53 ). Should strictly speak-
ing only be called circumﬂex when used over letters (“ê”),
otherwise caret.
|      Vertical line; pipe. Called “pipe” when used to for redirec-
tion (see above). In mathematics, used for absolute value,
norms, sets, cardinality, etc.
∼      Tilde.   Represents home directories on the command-
line. Can signify approximation, “∼ 10”, approximately ten,
“5.02 ∼= 5” (when the character ≈ can’t be used). The name
comes from Spanish, used for some foreign words.
’      Apostrophe, (single) quote. Quotes text. Can be confused
with several typographical characters, e.g. “ ” (prime) used
in mathematics and to represent units (feet, arcminutes,
etc.).

63
Common characters

Char                     Name Example of use
"      Double quote; (straight) quotation mark. Quotes text. You
differentiate between typographical quotes (“word” in En-
glish; ”ord” in Swedish) and straight quotes ("word") which

T
are also used for inches, arcseconds, etc.
As an aside, typographic conventions differ in American En-
glish, British English, and Swedish:

“Outer text with ‘inner text’”
‘Outer text with “inner text”’
”Yttre text med ’inre text’”

‘      Grave accent; backtick, backquote. Grave accent over let-

AF
ters (“è”); used in shellscripts to save the output of a pro-
gram’s stdout.
´      Acute accent. Acute accent over letters (“é”). Should not be
confused with an apostrophe.
DR

64
C   Selected applications

Programs             Category                                                Comment
Internet
Mozilla Firefox       Web browser       Standard browser on Ubuntu, also installed on other OSs.
Mozilla Thunderbird   Email             Standard mail reader for CSC’s Ubuntu.
SFTP                  File transfer     Ubuntu’s ﬁle manager (Nautilus) has builtin support for SFTP, but command-line versions
Selected applications

are also available.

Ofﬁce applications.
OpenOfﬁce             Ofﬁce suite       Free equivlaent of MS Ofﬁce and similar application suites. Contains the programs Writer,
Calc, Impress, etc.
A
LTEX                  Typesetting                                                              A
Creates typeset documents from a text ﬁle written in LTEX. Difﬁcult to master, but very
useful when writing lots of mathematical formulas.

65
LYX                   Typesetting                                      A                                  A
A word processor based upon LTEX. (Actually, a graphical shell to LTEX.)

Text editors
DR
gedit                                   An editor with the goal to provide a simple and easy to use tool for writing plain text. Supports
using plugins for advanced features.
emacs                                   Powerful editor et al. Handles all types of text, and has more tools than can be conveniently
named. The sheer number of features can make it difﬁcult to use for beginners.

Graﬁk, mediaapplikationer
GIMP                 Image processing   Advanced image editor.
Inkscape             Vector graphics    Application for SVG editing, and (to some extent) other vector formats.
XFig                 Vector graphics    Used to produce vector graphics, with emphasis on more spartan illustrations. Has support
A
for integration with LTEX.
Rhythmbox             Media player      The default media player of Ubuntu.
AF
GMplayer              Media player      Media player with a minimal GUI. Recognizes most media formats.
T
Programs         Category                                               Comment
VLC               Media player         Media player which recognizes a multitude of media formats.

Programming, Mathematics
Idle               Programming         Basic IDE for Python programming.
Eclipse            Programming         IDE for Java
Maple              Mathematics         Can handle both symbolic (algebraic) and numerical computation.
M ATLAB            Mathematics         Used for numerical programming. Contains a built-in IDE.

System tools
Appearance        Settings             Change the desktop and window appearance (background, theme, default fonts, etc.). System
→ Preferences → Appearance
Baobab            Account info         Show how much space a directory is using. Applications → Accessories → Disk Usage Analyzer

CSC tools

66
Sima              Course assistance    Queue used for laboratory exercises.
DR
Rapp              Course administra-   Used for internal course administration (storing lab results, etc). Handled by the course
tion                 leader, who after the course will enter the results into Ladok.
res               Course administra-   Older system for internal course administration. Terminal-based.
tion
AF
Selected applications

T
Index
*, see asterisk                         lpr, 28

T
>, <, |, see redirect                   lprm, 28
∼, see tilde                            ls, 26
man, see man pages
access rights, see AFS                  mg, 50
administrators, see Systemgruppen       mkdir, 26
AFS, 39                                 module, see modules
access rights, 29, 40, 42          more, 27
quota, 31, 40                      mv, 27
U NIX permissions vs., 29          nano, 50

AF
alt (key), see keyboard                 options for, 25
ASCII , see encoding                    overview & mnemonics for, 25
assistance, 55                          parameters, 25
asterisk, 63                            pico, 50
as wildcard, 26                    pts, 40
in ﬁle listings, 26                pwd, 25
Autodesk Maya, 18                       quick guide, 71
res, 59
backup, 40                              rm, 27
Baobab, 9                               rmdir, 26
bash, see shell                         rsync, 27, 29
functions, 38                        sed, 37
sima, see Sima Manager
Chromium, 9                             ssh, sftp, scp, 9, 43
command-line, 23–34                     tar, 27, 29
details, 35–46                       terms used w. regard to, 32
interface (CLI), 23                  tokens, 39
Commands, 24                            tr, 37
DR
a2ps, 27                         computer account
alias, 38                            CSC or KTH, 57
apropos, 55                      computer mouse, 3
awk, 37                          control (key), see keyboard
bg, 31                           courses
cat, 27                              administrative tools, 59
cd, 25                           Creative Suite, 18
chmod, 29                        CSC, see also KTH
course, 42, 59                       computer rooms, 1
cp, 27                               computers at, iv
diff, 37                             work environment, rules for, v
echo, 31
emacs, see Emacs                 directories, see also ﬁlesystem
fg, 31                               access rights in, 42
fs la, sa, 29, 41                    creating and removing, 26, 27
fs lq, 40                            sharing, 41
fs mkm, 41                       Disk Usage Analyzer, see Baobab
functions, see bash              Documentation, 54
grep, 37                             online, 55
iconv, 6                         Dreamweaver, 18
info, 54
kauth, kinit, klist, 39          Eclipse, see Programming
kdestroy, 46                     Emacs, 47–50
kill, 31                             quick guide, 72
kpagsh, 45                           tilde ﬁles, 49
less, 27                         encoding, 6
ln, 28                               iconv, 6, 27
lpq, 28                          environment variables, 38

67
Index

Evolution, 9                           M ATLAB, see Programming
Maya, see Autodesk Maya
FAQ, 56                                meta (key), see keyboard
ﬁle storage, 1, see also AFS           modiﬁer (key), see keyboard
ﬁlesystem, see also AFS                modules, 21, 38

T
ﬁles in, 33                        mouse, see computer mouse
Final Cut Pro, 18                      MS Ofﬁce, see also OpenOfﬁce
Firefox, 9                                 Excel, 17
for Mac OS X, 17
gedit, 11                                  Powerpoint, 17
G IMP, 10                                  Word, 17
Gnome
create launcher, 9                 Octave, see Programming
Gnome Desktop, 7                       OldFiles, see backup

AF
GSSAPI, 45                             OpenOfﬁce, 10
GUI, Graphical User Interface, 3, 62   operating system, iv
X11 forwarding, see SSH            OS X, see Mac OS X

home directory, see ﬁlesystem          password, see kpasswd
homepage, personal, 42                     multiple KTH, 24
problems changing, 57
iconv, see encoding                    path, 24, 33
IDE, see Programming                   permissions, see AFS
Illustrator, see Creative Suite        Photoshop, see Creative Suite
InDesign, see Creative Suite           pipeline, see redirect
Inkscape, 11                           plain text, 11
ISO-8859-1 (Latin-1), see encoding     PostScript, 28
iWork (OS X), 17                       Printing, 27
printing
Java, see Programming                      Mac OS X, 19
Java Desktop System, 21                    Ubuntu, 12
process, 31
DR
Kerberos, 2, 39                        program (concept), 31
at home, 45                        Programming, 51–53
commands, 39                       prompt, 24
kdestroy, 46                       public_html, see homepage
kpagsh, 45                         Python, see Programming
telnet, ftp, 43
tickets, 31, 57                    quota, see AFS
keyboard, 3                               over, 57
compose (key), 4
Keychain (OS X), 16                    redirect, 36
kpasswd, 24                            remote access, see SSH
KTH
rules of conduct, v                Safari, 16
schedule, v                        script, 23, 35
settings
LTEX, 13
A                                          restore default, 58
LYX, 13                            shell, 24
TEXShop, 18                             wrong, 58
link, ﬁle system, 28                   shift (key), see keyboard
login, 1, see also Ubuntu, Mac OS X    Sima Manager, 55
failsafe, 7, 20                    Solaris, see also encoding
at CSC, 20–22
Mac OS X                                    logging in, 20
at CSC, 15–19                       SSH, 9, 43
logging in, 15                           Kerberos and, 45
man pages, 54                          standard input/output/error, see
markup language, 13                             redirect
mathematics                            SunRay clients, 20
typesetting, 13                     support, 56

68
Index

suspend, see program
symbolic link, see link
Systemgruppen, the KTH CSC Sys-
tems Group, 56

T
tab completion, 24, 26, 36
tcsh, see shell
thin clients, see SunRay clients
Thunderbird, 9
tilde
as path, see ﬁlesystem
ﬁles, see Emacs

Ubuntu

AF
at CSC, 7–14
history, iv
logging in, 7
U NIX
history of, iv
U NIX
FAQ, 25
USB
Mac OS X, 16
problems with, 57
Ubuntu, 12
UTF-8, see encoding

whitespace, 62
quoting, 32
wildcards, 26, 35

X11 forwarding, see SSH
DR

69
70
DR
AF
T
D     Quick guide to U NIX commands

D.1    Information, documentation, user info                                                 sort                  Sort the contents of one or more ﬁles.
apropos word                Look for man page with the keyword word.                         tail filename         Display the end of ﬁlename.
date                        Show current date and time.                                      tee newfile           Send output both to a ﬁle and to the screen.
man subject                 Show man page for subject.                                       tr                    Translate (replace) characters.
who                         Show users logged in to this computer.                           uniq filename         Show all unique lines of ﬁlename.
wc filename           Count the number of characters, lines and words of ﬁlename.
zcat                  Like cat, but for compressed ﬁles.
D.2    Commands, process management                                                          zmore                 Like more, but for compressed ﬁles.
bg                        Put suspended process in background.
cd                        Change working directory.
clear                     clear terminal window.                                             D.4   File access
echo arg                  Show arg, e.g. echo $PATH. chmod Change permissions for ﬁle(s). exit Exit the shell (terminal). fs [la|sa] Show or change AFS access control lists. fg Put suspended process in foreground. cp from to Copy the ﬁle from to to. jobs List active processes. cp file directory Copy the ﬁle to the directory. kill PID Kill process with ID PID, see ps below. df Disk usage, for local ﬁlesystems only!. kpasswd Change password. fs lq Quota usage, AFS. program & Execute program in the background. du Show disk usage of a ﬁle and/or directory. ps List processes and their PIDs, see kill above. find Find ﬁles, directories, etc. ps -C program Ubuntu: List all processes named program file filename Determine ﬁle type heuristically. ps -u user Ubuntu, Solaris: List all processes owned by user gzip Compress ﬁles. ps -elf Ubuntu, Solaris: List every process, using long and full listing gunzip Uncompress ﬁles (see also tar) pwd Print working directory (see cd above). ln -s Create a symbolic (soft) link. DR stty Avläs eller sätt terminalparametrar. ls List contents of the current directory. ssh Remote login on another computer. ls -l . . . using a detailed listing. time command Measure time for command. mkdir directory Create subdirectory directory. mv from to Rename the ﬁlefrom to to. mv file directory Move the ﬁle ﬁle to the directory. D.3 Text and data in ﬁles and pipes rm file1 file2... Remove the ﬁle(s). cat file1 file2 Display ﬁle1 och ﬁle2 as a single ﬁle. rmdir directory Remove the directory. cmp Compare the contents of two ﬁles. sftp host Move ﬁles to/from the computer host. comm Compare the lines of two sorted ﬁles. tar Archive utility. file-roller is a graphical alternate. cut Choose columns from every row of a ﬁle. diff Compare the contents of two ﬁles. emacs Run the editor GNU Emacs. D.5 Printing grep text filename Search for text in the ﬁle ﬁlename. a2ps -Pprinter file (Ubuntu) Print the ﬁle ﬁle on the printer printer. head filename Display the start of ﬁlename. print -Pprinter fil (Solaris) Print ﬁl (PostScript or text) on printer. less Page through ﬁles. Can page backwards. lpq -Pprinter Show the queue for printer. more Page through ﬁles. lprm -Pprinter n Abort job n on printer. paste Merge lines from different ﬁles. AF T E Quick guide to Emacs E.6 Moving around <spc> or y replace, go to next C-g abort Escape can be used as Meta. ESC x is the same as M-x, ESC C-x = <Del> or n don’t replace, go to next M-p, <up> previous command ¯ ¯ ¯ Move cursor , replace, don’t go to next M-n, <down> next command C-M-x, etc. ¯ <left> or C-b character forward ! replace all remaining matches E.1 Start and stop Emacs <right> or C-f character back ˆ go back to previous match M-f word forward E change replacement string emacs (on command-line) start Emacs M-b word back <Return> or q exit E.14 Buffers C-z graphical mode: iconify Emacs <down> or C-n row down text mode: suspend Emacs C-x C-b list all buffers <up> or C-p row up fg (command-line) resume Emacs C-x b switch to buffer C-a move to beginning of line E.10 Multiple windows and frames C-x C-c exit Emacs C-x k kill buffer (close ﬁle) C-e move to end of line An Emacs “window” is part of the “frame” (program window). M-e sentence forward C-x 1 remove all other windows E.2 Filer M-a sentence backward C-x 0 remove this window C-x C-f open ﬁle M-< move to beginning of buffer C-x 2 split to two windows, horizontally E.15 Replace text C-x C-s save ﬁle M-> move to end of buffer C-x 3 split to two windows, vertically C-v scroll forward C-t swap with previous char C-x i insert contents of ﬁle in current buffer C-x o select next window M-t swap previous word C-x C-w save as (can overwrite existing ﬁle) M-v scroll backward C-x 5 2 create new frame C-x < scroll left C-x C-t swap previous line C-x 5 0 remove this frame C-x > scroll right E.3 Help Press C-h and follow the instructions. For beginners, press C-h t for a E.11 Formatting E.16 Spell check tutorial. ¯ E.7 Delete text <tab> indent line (depending on current mode) C-d or <del> character forward C-M-\ indent region (depending on mode) M-$                         check spelling of this word
C-M-v scroll the help window
<bak>            character backward               C-o        insert linebreak after cursor                     M-x spell-region            check spelling of region
C-x 1 remove the help window
M-d              word forward                     C-M-o      move rest of line down                            M-x spell-buffer            check spelling of buffer
C-h a apropos: show commands matching text
C-h c describe key (brieﬂy)                                               M-<del>          word backward                    C-x C-o    remove surrounding blank lines
C-h f describe function                                                   C-k              rest of line (kill)              M-\        remove blankspace around point
C-h m show information on current mode                                    M-k              rest of sentence                 M-q        ﬁll paragraph (even out margins)
C-M-k            rest of balanced expression      M-g        ﬁll region
E.17         Info
C-w              kill active region (cut)         C-x f      set right margin for lines                        C-h i               start Info
E.4         In case of errors                                             M-z tkn          delete to next char tkn          C-x .      set preﬁx for lines                               SPC                 go forward within this node
M-x recover-file         recover ﬁle after program crash                  C-y              yank last kill (paste)                                                                        Del                 go back within this node
M-y                                                                                                            . (period)          to start of node
DR
C-g                      abort partial command                                             replace yanked text with older
C-x u or C-_             undo latest change                                                                                 E.12      Change case                                        n                   to next node
M-x revert-buffer        revert to saved ﬁle                                                                                M-u      change word to UPPERCASE                            p                   to previous node
C-l                      redraw and recenter screen                       E.8     Mark                                      M-l      change word to lowercase                            u                   up one level
C-<spc> or C-@ set mark here                      M-c      capitalize (ﬁrst letter)                            ?                   show Info commands
C-x C-x        jump from point to mark            C-x C-u  uppercase region                                    q                   quit Info
E.5         Search                                                        M-h            mark paragraph                     C-x C-l  lowercase region
C-s         search forward                                                C-x C-p        mark page                          M-x capitalize-region
C-r         search backward                                               C-M-h          mark function                               like M-c but for region
C-x h          mark entire buffer                                                                              E.18         Keyboard macros
Press C-s or C-r repeatedly to search again                                                                                                                                              C-x (                           start recording key macro
<Return>          exit search                                                                                               E.13      Mini buffer                                        C-x )                           end recording
<Del>             undo last keypress                                      E.9     Search-and-replace                        These keys can be used in the minibuffer.                    C-x e                           execute last saved macro
C-g               abort search                                            M-%              S&R interactively                <tab>         complete as much as possible                   C-u C-x (                       extend last macro
SPC           complete a single word                         M-x name-last-kbd-macro         bind macro to a name
If Emacs is still searching, C-g will stop that search. Otherwise, the    Possible answers are                              <retur>       complete and execute                           M-x insert-kbd-macro            show lisp code of macro
entire search is aborted.                                                                                                   ?             show possible completions
AF
T


DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 39 posted: 8/2/2011 language: English pages: 80
How are you planning on using Docstoc?