Self Study Guide: Linux
Total Page:16
File Type:pdf, Size:1020Kb
University of Cambridge Department of Physics Computational Physics Self-study guide 1: PWF Linux Dr. Rachael Padman Michaelmas 2007 Contents 1.1 The Workstation 2 1.2 Logging in to PWF Linux 2 1.3 The Linux Desktop 4 1.5 Manipulating windows 6 1.6 Two Unix commands 7 1.7 Finishing 8 2 INTRODUCING UNIX COMMANDS 9 2.1 Log in to PWF Linux 9 2.2 The date command again 9 2.3 Creating a new window from the command line 9 2.4 Removing the xterm window 9 2.5 More about the & - background and foreground tasks 10 2.6 Files and directories 10 2.7 Directories 12 2.8 Local line editing 13 2.9 Getting help and information online 14 3 EDITING 16 3.1 Setting up a text file – emacs 17 3.2 Making use of multi-tasking 19 3.3 Leaving emacs 19 3.4 The spell command 19 3.5 Correcting the mistakes 20 3.6 Some emacs commands 20 3.7 Further use of emacs 21 3.8 The emacs undo command 22 3.9 emacs: deleting lines, cutting and pasting 22 Appendix: emacs commands 23 4. FURTHER USE OF UNIX AND EDITING WITH X 24 4.1 Stopping a running program 24 4.2 Sending output to a file 24 4.3 Pipes 24 4.4 Highlighting and copying text 25 4.5 Printing 25 Acknowledgements: This handout was prepared by Dr. Paul Alexander, and has been updated by the previous lecturer, Dr Peter Haynes of the TCM group. 1 1. Logging into PWF Linux and the Linux Desktop This document explains how to use Linux (a widely available free version of Unix) on the Physics Public Workstation Facility (PWF). The local term refers loosely to a Personal Computer together with its connection to a network. At first mention in this document, any technical term is written in italics. You may be able to skip some aspects of the guide if you are familiar with either Linux or some other version of Unix. If you have never used Linux or Unix before then you should aim to work through to at least section 3.5 before moving onto the next self-study guide. The material in sections 3.6 and later can be returned to as needed later on. We will often use the terms Linux and Unix interchangeably, but you may assume that whenever we say Unix then that statement refers to all versions of Unix, including Linux. It is assumed that you are have a PWF account. If you have forgotten your password on the PWF then it can be reset by the classes technician; please speak to him or your head of class. 1.1 The Workstation • Sit down at a PC workstation. The main components are a screen (or monitor), a computer, a keyboard and a mouse. • Certain keys on the keyboard are engraved with cryptic symbols. Note particularly: 1. The SHIFT-keys each of which is engraved with an open up-arrow, ×. 2. The TAB-key which is engraved with a pair of arrows, ). 3. The ENTER-key is engraved with a bent left-arrow, . 4. The BACKSPACE-key which is engraved with a straight left-arrow, ←. • The ENTER-key is normally pressed at the end of each line of input. It must not be confused with the Enter-key which is at the extreme right-hand end of the keyboard. This latter Enter-key will never be used in this course. • The BACKSPACE-key is used for correcting mistakes; it cancels the character most recently keyed in. 1.2 Logging in to PWF Linux Each Physics PWF computer can either run the Windows Operating System (OS) or the Linux OS. • Everyone has a different personal identifier (CRSid) and password and this is the same whether you are using Windows or Linux on the PWF. 2 • If the computer is not switched on switch it on at the wall sockets and on the workstation and screen as well if necessary. • If the computer is currently running Windows then you need to logout and restart the computer; select “Shut Down…” from the Start menu, then “Shutdown and Restart” and when prompted select “OK”. • When the computer starts (or restarts if previously running Windows) you will be offered a “OS Loader” menu which looks something like: PWF Microsoft Windows PWF Linux You have 30 seconds to select the operating system you wish to run using the cursor keys (↑, ↓). Select PWF Linux. • After a short while another menu appears. PWF Linux is now the default and will be automatically selected after ten seconds or when you press ENTER. • After about two minutes a message window will appear asking you to accept the conditions of use of this machine – click on “OK”. • Finally you are presented with a Login screen in which you should enter your CRSid and password. It is very important to realise that Unix is case sensitive and therefore the CRSid’s spqr1 and SPQR1 are different. 3 1.3 The Linux Desktop Once logged on the Linux Desktop will appear as in the following figure: Under Unix the program which provides the Graphical User Interface (GUI) that you are now using is called “X”, and therefore the windows which appear on the Desktop are often referred to as X-windows. The Linux Desktop is in many ways similar to the Microsoft Windows desktop, but there are some differences. In particular under Linux there are many different window managers – PWF Linux runs GNOME. At the top of the screen is a menu bar: launch an start a WWW date and application browser time At the bottom of the screen you see a task bar similar to the task bar under Windows: list of running the virtual applications desktop The Applications menu (top left) is much like the Start menu under Windows and gives a menu of applications to run. 4 1.4 Launching a terminal window and other applications The X terminal or xterm application is particularly important and may be launched from the Applications menu: • When you select the xterm item by the icon a new window appears. • The xterm provides a way of giving commands – unlike Windows we shall interact with Linux mainly by means of commands typed into an xterm. However, before we do this we shall first see how to move and manage multiple windows on the desktop. 5 1.5 Manipulating windows Each window has a title bar with a set of buttons as shown below: options title bar minimise maximise close The buttons to the top right of the window have the same meanings as under Windows. • Try minimising the xterm window by clicking on the left button. To get the window back you should click on the xterm icon in the list of current applications (bottom left) or you can click on the window list icon in the top right of the desktop and select from a list. • Try maximising the window by clicking on the middle button; the same button will return the xterm to its original size. • Now dismiss the xterm by clicking on the close button; you can launch another xterm from the Applications menu. Windows can be moved by clicking with the left button on the title bar, then while holding down the left mouse button the window will move with the mouse pointer. Windows can overlap each other: to bring a window to the front so that it is completely visible (raise the window) simply click on the title bar. • Try moving and raising the windows you have; you may like to create a second xterm window. 6 When you are using the mouse it is clear which window you are interacting with – input from the terminal is directed to the window which has “focus” – this is the window which has a blue title bar rather than a white one. • Move the mouse pointer away from the xterm and click on the empty desktop – the title bar becomes white and the text cursor is a hollow rectangle. Text cannot be typed; try doing so. • Now move the mouse pointer into the xterm window and click. The text cursor changes to a solid black box and the window is highlighted by a blue border and text may now be typed. Any text that is typed will appear at the text cursor and not at the mouse pointer. Changing the size of the window is done by moving the mouse pointer over any part edge or corner of the window; note how the mouse pointer changes shape. Once positioned over the edge of the window click and hold down the left mouse button, and now while still holding down the left mouse button “drag out” the new size of the window. Some windows are of fixed size and cannot be changed in this way. • Experiment by changing the size of the xterm window. 1.6 Two Unix commands Unix is a very powerful system, but most of the power is available only via commands typed into the system. The xterm provides a Command Line Interface (CLI) to Unix. Just as with desktops so Unix supports many different CLI’s, some general purpose, some specialised; the Unix term for a program which provides you with a CLI is called a shell. The shell you will use is called bash (you will only need to know this if you try to look up information about the shell in the system documentation). We will introduce this idea here and return to consider in more detail this important aspect in the next section.