Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

Embed Size (px)

Citation preview

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    1/133

     

    Linux Operating SystemULNXC-14

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    2/133

     

    Linux Operating System

    ULNXC-14

    Compiled by: Daniel M Le Roux

    Updated by: James Forsyth and Brendon Gouws

    Quality assured by: JP Pretorius

    Edited by: Ali Parry

    Version 1.0

    ©November 2013 CTI Education Group

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    3/133

     

    TABLE OF CONTENTS

    INTRODUCTION TO LINUX  1 Module overview  1

     

    Module structure  2 

    Additional supplementary reading 2 

    Learning outcomes and assessment criteria  3 Icons used in this study guide  3 The history of Linux  4 Ubuntu Linux  6 What is Linux? 6 Using the Linux operating system  7 The three main parts of the Linux system  8 The Linux Graphical User Interface  9 

    UNIT 1 – INSTALLING AND CONFIGURING UBUNTU  12 

    1.1 

    Installing Ubuntu  15 

    1.2 

    Configuring Ubuntu  21 

    UNIT 2 – THE LINUX FILE SYSTEM  23 2.1

     

    The three main parts of the Linux file system  23 

    2.2 

    File types  23 

    2.3 

    File names  24 

    2.4  Directory files  24 2.5  The directory structure  26 2.6  Searching for files  27 

    UNIT 3 – THE LINUX TERMINAL  30 3.1  Terminal basics  30 3.2  The Linux prompt  33 3.3  System identification  34 3.4  Linux command syntax  36 3.5  Getting help  41 

    UNIT 4 – WORKING WITH DIRECTORIES  44 4.1

     

    Directory commands  44 

    UNIT 5 – WORKING WITH FILES  49 

    5.1 

    Basic Linux file commands  49 

    5.2 

    Creating a simple text file  50 

    5.3 

    Viewing files  52 

    5.4  File security  60 

    UNIT 6 – INPUT AND OUTPUT  70 6.1  Input and output files 70 6.2  Redirecting the standard output file  71 6.3  Redirecting the standard input file  72 

    6.4 

    Redirecting the standard input and standard output 73 6.5  Redirecting the standard error file  73 

    6.6  Pipelines  73 6.7  Filters  75 

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    4/133

     

    6.8  Sampling data in a pipeline  76 

    UNIT 7 – LINUX PROCESSES  79 7.1  Process status  79 7.2  Running processes in the background  80 7.3  Terminating processes  81 

    UNIT 8 – MOZILLA FIREFOX  84 

    8.1  The features of Mozilla Firefox  84 8.2  Configuring Mozilla Firefox  86 

    UNIT 9 – MOZILLA THUNDERBIRD  99 9.1

     

    Introduction to Mozilla Thunderbird email  99 

    9.2 

    The features of Thunderbird  99 

    9.3 

    Setting up an email account  100 

    9.4 

    Personalising Thunderbird and configuring account settings  105 

    UNIT

    10 –

     M

    OREA

    PPLICATIONS  107

     

    10.1  LibreOffice  107 10.2  GNU Image Manipulation Program (GIMP)  113 10.3  The Workspace switcher  114 

    ANSWERS  116 

    UNIT 11 – THEORY AND PRACTICAL EXAMINATIONS  118 11.1  Theory examination  118 11.2  Practical examination  118 

    EXERCISE CHECKLIST  119 

    GLOSSARY  120 

    LINUX OPERATING SYSTEM – EVALUATION FORM  128 

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    5/133

     

    Linux Operating System | V1.0 Nov 2013 Page 1 of 133

    Introduction to Linux 

    Welcome to CTI’s module on using the Ubuntu Linux operating system.

    The module will introduce you to open source software and the increasinglyimportant role it plays within the IT world. You should already be wellacquainted with the Windows operating system, which means that many of theconcepts and techniques presented in the module will seem familiar. Pleaseread all the material in this study guide very carefully. On the surface Linuxmay seem to be very much like Windows, but as you work through the studyguide you will discover that they differ in many ways.

    Module overview 

    This module is aimed at teaching the basic principles of using the Linuxoperating system to run applications and manage files. It is thereforerecommended that you spend as much time as possible working on the Linuxsystem to gain a thorough understanding of the operating system.

    Unlike other operating systems, Linux offers a wide variety of systemsdesigned for specific uses by incorporating highly specialised applications.

    There is no single, definitive Linux operating system. In fact, there are over200 kinds of Linux, known as Linux distributions, each offering differentvarieties of desktop environments and applets. Some of the more well-knownLinux desktop distributions include Mint, Ubuntu, Fedora, Mageia and Debian.It is interesting to note that Android, the mobile OS, is technically the mostwidespread Linux distribution as it uses, and was built from, the Linux kernel.

    NOTE This module and all examination questions are based on the Ubuntudistribution of Linux, version 12.04.

    The module begins with a brief history of Linux and the background of theUbuntu distribution to help you understand the nature and spirit of theoperating system, and then introduces you to using Linux through a GraphicalUser Interface. Although the interface resembles the Windows desktop in manyways, a look behind the scenes at the underlying Linux file system will uncoversome of the main differences between them as an introduction to the Linuxcommand line interface. This is where the true nature and power of Linux isrevealed.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    6/133

     

    Linux Operating System | V1.0 Nov 2013 Page 2 of 133

    If you are interested in reading more about current developments in Linux, youare encouraged to visit the following websites:

    •  www. l i nux. com

    •  www. ubunt u. com

    • 

    www. l i nuxnewbi e. com•  www. go- opensource. org

    Module structure 

    Table 0.1 – Suggested work schedule

    Introduction, Units 1 and 2 1 day

    Units 3 – 6 1 day

    Units 7 – 10 1 dayTheory examination 1 day

    Practical examination 1 day

    Additional supplementary reading 

    The following two textbooks are for additional reading purposes only. Theymay be borrowed from the campus library to further your understanding oftopics in this module:

    •  Helmke, M. and Graner, A. 2012. The Official Ubuntu Book,7th edition. Prentice Hall Pearson Education. ISBN13:9780133017601

    •  Helmke, M. 2012. Ubuntu Unleashed, 2012 edition. PearsonEducation, Inc. ISBN13: 9780672335785

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    7/133

     

    Linux Operating System | V1.0 Nov 2013 Page 3 of 133

    Learning outcomes and assessment criteria 

    Assessment for pass:

    A pass is awarded for the unit on the achievement of all the pass assessment

    criteria.

    Learning outcomes Assessment criteria for pass

    To achieve each outcome a studentmust demonstrate the ability to: 

    LO1Use the Linux operating system’sdesktop

    P1.1 Use an application in GNOMEP1.2 Use the GNOME help browserP1.3 Modify preferences in GNOMEP1.4 Use the GNOME desktop

    LO2Work with files and folders, anduse the Linux operating system’sterminal and commands

    P2.1 Use the Nautilus File ManagerP2.2 Illustrate the use of different file

    typesP2.3 Use a Linux terminalP2.4 Use Linux commands

    LO3

    Use a Linux text editor,applications, applets and utilities

    P3.1 Manipulate a document using the vitext editor

    P3.2 Use different applications andutilities within Linux

    P3.3 

    Use an applet within Linux

    Icons used in this study guide 

    Some conventions have been used to make this guide easier to follow. Whenkeys on the keyboard are referred to, they are in angle brackets and bolded,e.g. refers to the Delete key on the keyboard.

    •  When two or three keys are pressed simultaneously, they are placed next to

    each other and bolded, e.g. ; this means press the Ctrl and Altkeys at the same time.

    •  Where a menu item is referenced, the item has been printed in bold.

    •  In the section on the command line interpreter, a different font is used forcommands and any text that you must type.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    8/133

     

    Linux Operating System | V1.0 Nov 2013 Page 4 of 133

    Indicates start of each main unit in the study guide.

    This symbol is found at the beginning of each unit. It states theoutcomes for each unit.

    This symbol is found wherever there are labs to be completedby the students on the computer.

    This symbol is found at the end of certain units, and providesyou with a few practice questions to test your knowledge of thepreceding units.

    The history of Linux 

    The Linux story began with Unix, an operating system written by KenThompson, Brian Kernighan and Denis Richie at Bell Laboratories in the late1960s. Unix was written to replace the Multics operating system onminicomputers and mainframe computers. Unix was originally written inAssembly language, which meant that although it was fast and could interactdirectly with computer hardware, it could not be used on computers withdifferent hardware without changing the Assembly code. Consequently, Unixwas rewritten in C in the early 1970s.

    Rewriting Unix in C made it more portable from one computer system to

    another. However, Unix was still not very user-friendly because it was writtenby engineers and programmers for engineers and programmers, and was notsuitable for use on the new generation of desktop computers.

    After Thompson introduced Unix to the University of California at Berkeley inthe mid-1970s, staff and students continued to develop Unix enhancements,many of which were included in later versions of the system. Unix continues toevolve through the contributions made by the universities, researchorganisations and commercial groups that still use the operating system.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    9/133

     

    Linux Operating System | V1.0 Nov 2013 Page 5 of 133

    The first step towards Linux from Unix was taken in the 1980s when AndrewTanenbaum, a computer science professor in the Netherlands, wrote aneducational version of Unix called Minix. The purpose of Minix was for studentsto learn Unix on home-based Intel PCs.

    In August 1991, Linus Torvalds, then a student at the University of Helsinki inFinland, posted the following message to the Minix newsgroup:

     ‘Hello everybody out there using minix –I’m doing a (free) operating system(just a hobby, won’t be big and professionallike gnu) for 386 (486) AT clones.’

    The result of this hobby was Linux, a Unix-like operating system for personalcomputers! By creating Linux, Torvalds was able to provide the core of a Unix-

    like operating system, without all the restrictions associated with Unix itself.Linux is more user-friendly, runs on PCs, and is relatively inexpensive. Thefirst real version of Linux became available in 1994 – using less than 2 MB ofRAM at amazing speeds.

    Linux explored the task switching capabilities of the Intel 80386 chip, andalthough it is still mostly used on Intel-based PCs, it now runs on a widevariety of hardware, including the full x86 family of processors, such as AMD-based PCs.

    While Torvalds is responsible for the core of the Linux operating system,known as the kernel, many other programmers have added utilities andapplications to the basic kernel and created what are known as Linuxdistributions. As mentioned earlier, there are over 200 Linux distributions, butthe distributions you are most likely to encounter (on desktop and servercomputers, at least) are Mint, Fedora, Mageia, Ubuntu, Debian, Slackware andopenSUSE. Much of the work that has gone into Linux distributions comesfrom the GNU project of the Free Software Foundation.

    GNU is a self-referential acronym that stands for GNU’s Not Unix. To find out

    more about the GNU project and the General Public Licence, visit www. gnu. or g.One of the most important decisions made in the early days of Linux was tomake the source code freely available and distributable, and to make it subjectto the GNU General Public Licence. This licence guarantees your freedom toshare and change the software, which means that anyone:

    •  May distribute copies of the software and charge a fee for distributing it,should have access to the source code, and may change the software or usepieces of it in new free programs.

    •  Should know they may do these things.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    10/133

     

    Linux Operating System | V1.0 Nov 2013 Page 6 of 133

    Ubuntu Linux 

    The Ubuntu story began in 2004 when Mark Shuttleworth got a group of opensource developers together to create a new Linux-based desktop operatingsystem. The result of this was Ubuntu, an operating system based on a strongDebian foundation and the GNOME desktop environment. The Ubuntu projectis sponsored by Canonical Ltd, a company owned by Mark Shuttleworth.

    October 2004 saw the first release of Ubuntu version 4.10, also known asWarty Warthog. All Ubuntu releases thereafter used the same namingnotation, and all carry a similar alliterative name, e.g. Breezy Badger, Edgy Eftand Feisty Fawn. Ubuntu 12.04 is known as Precise Pangolin.

    The name ‘Ubuntu’ comes from an ancient African phrase “Umuntu ngumuntungabantu”, which roughly translates into “a person is a person through

    people”.

     “A traveller through our country would stop at a village, and he didn’t have toask for food or for water. Once he stops, the people give him food andentertain him. That is one aspect of Ubuntu but Ubuntu has various aspects.Ubuntu does not mean that people should not enrich themselves. Thequestion therefore is: Are you going to do so in order to enable thecommunity around you to improve?” – Nelson Mandela.

    The Ubuntu Linux distribution is aimed at bringing the philosophy of Ubuntu to

    the software world. There are also other variations of Ubuntu available, e.g.gobuntu, edubuntu, xubuntu and kubuntu. There is also the Freedom Toasterproject, which is aimed at making it easier to access open source software bygiving the public the opportunity to freely burn open source software onto

    discs. For more information, visit the website at www. f r eedomt oast er . org.

    What is Linux? 

    Linux is a multi-user, multitasking operating system.

    Linux is firstly an operating system. An operating system is the softwarethat controls the computer’s use of its hardware resources, and acts as aliaison between the computer hardware and the application software. Itsresponsibilities include:

    •  Managing the resources

    •  Controlling input and output•  Managing storage space

    •  Detecting equipment failure

    • 

    Maintaining system security

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    11/133

     

    Linux Operating System | V1.0 Nov 2013 Page 7 of 133

    Linux is a multitasking operating system. This means that Linux manages itsresources in such a way that it can handle several different programs at thesame time. Being able to perform several tasks at the same time leads to themore productive use of a single machine’s resources. Linux uses pre-emptivemultitasking in that the operating system (rather than the application) controls

    tasks and the allotment of clock cycles to applications.

    Linux is also a multi-user operating system. More than one user can accessthe system at the same time, and the operating system ensures that all theusers logged onto the system share the resources of the computer. This alsomeans that these users can share expensive equipment such as printers.

    Other features of Linux include:

    •  Linux is an interactive operating system, meaning commands instructing

    the system to do certain tasks can be entered and the system respondswith appropriate output.

    •  Linux has a demand-paged virtual memory system that means it can runprograms requiring more memory than the system’s installed RAM hasavailable.

    •  Security is built into the operating system.

    •  It uses full 32- or 64-bit memory access.•  Linux can coexist peacefully with other operating systems (such as

    Windows) in different partitions on the same hard disk.•  Linux has one of the most wide-ranging hardware compatibility lists for any

    operating system. When someone needs a driver for a new piece ofhardware (for which there are no drivers available), they can just write adriver and make it freely available.

    •  Linux is a Unix clone written completely from scratch retaining much ofUnix’s functionality, with some added extras.

    Using the Linux operating system 

    Linux can be used in a variety of environments, from the small home user to

    large companies:

    •  Personal workstation –  Linux can be set up to run as a standaloneworkstation in the home, or be part of a network where it can act as a clientworkstation. Linux can also share files with other operating systems, suchas Microsoft Windows 7 and Microsoft Windows Server 2008. 

    •  Server – Linux can act as a file and print server because of its powerfulmultitasking abilities, virtual memory and file system. It also provides thesecurity tools necessary to control access to a server. It is often used byInternet Service Providers to provide Internet access services to theirclients.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    12/133

     

    Linux Operating System | V1.0 Nov 2013 Page 8 of 133

    The three main parts of the Linux system 

    The Linux operating system is made up of three main parts or levels: kernel,shell and utilities (see Figure 0.1).

    Figure 0.1 – The three main levels of the Linux operating system

    •  Kernel – the kernel is the heart of the operating system and communicatesdirectly with the system hardware. The kernel:o  Controls hardware resources such as memory, terminals and printers.o  Schedules and executes programs.o  Manages the file system.o  Controls input and output.o  Tracks who is logged on to the system.

    •  Shell – the shell provides an easy connection, or interface, between the

    user and the kernel. There are two kinds of shells: graphical user interfaceshells and command line shells.o

      Graphical user interface shells enable users to select icons from avirtual desktop (using a mouse or other pointing device) to carry outrequired tasks. The X Windows System provides this capability in Linuxsystems.

    Tools

    Utilities

    Shell

    Kernel

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    13/133

     

    Linux Operating System | V1.0 Nov 2013 Page 9 of 133

    o  Command line shells (also called command line interfaces) are used

    to issue commands to the shell, and are used by more experiencedusers as they provide full access to the system. In this module, you willaccess the command line from the desktop. There are severalcommand line shells available (the command to run the shell is given in

    brackets):  Bourne shell (sh):  Named after its creator, Stephen Bourne, it is

    one of the earlier shells that provide little help to the user (such asediting commands typed at the command line).

      C shell (csh): Written at Berkeley, it is so called because it derivedits command set from the syntax of the C programming language.Again, there is little of the user-friendliness of the newer shells.

      Enhanced C shell (tcsh):  This is the C shell with some additionaluser-friendliness.

      Bourne-again shell (bash):  This is the most popular Linux shell

    because of its features and user-friendliness. It is a widely availableLinux shell developed from the Unix Bourne and C shells, with someadded features, by the GNU project.

    Utilities and applications form the third layer. They are executable programswritten to do particular jobs well. The advantage of this approach is itsflexibility in that you can add whatever programs you require to customiseyour environment.

    The Linux Graphical User Interface 

    X Windows provides a Graphical User Interface (GUI) for Linux that iscompletely configurable, with a broad range of flexible options. Linux isdistinct from a GUI like Microsoft Windows in that the Linux GUI separates theinterface from the windows, and thus it requires two components: the X Serverand a window manager. The X Server controls the display and is responsiblefor all input and output. In Linux systems, X Windows is just one piece of theoperating system – the windowing environment.

    The X Server sets up the graphics display (i.e. resolution, refresh rate, colourdepth, and so on). It also displays the windows, and tracks mousemovements, keystrokes and multiple windows. It does not, however, providemenus, window borders, or the capability to minimise or maximise windows.These are provided by the window manager. Typically, the Linux kernelcommunicates between X Server and the computer’s hardware. The mostcommon X Server that is used is XFree86 because it is free and its full sourcecode is available. There are also commercial X Servers on the market of whichthe main ones are Metro-X and Accelerated-X.

    A window manager provides all the extra features that make an X Windowsenvironment a true Graphical User Interface, including colour backgrounds,and sophisticated window borders and menus. This is the component thatcontrols the appearance of the windows.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    14/133

     

    Linux Operating System | V1.0 Nov 2013 Page 10 of 133

    These managers are themselves highly customisable, allowing you to choosethe look and feel of the X Windows system. It is here that the flexibility of XWindows is best seen. Since the windowing layer is separated from the userinterface layer, it allows the creation of many different window managers thatare complete redesigns of the user interface (rather than just the subtle

    differences in appearance that Microsoft Windows provides). The main windowmanagers around today include FVWM (the meaning of the F has been lost, butVWM stands for Virtual Window Manager), Afterstep, IceWM andEnlightenment.

    Although there are many different X Servers and window managers, theycommunicate with one another in a predefined manner. This ensures that awide range of applications can talk to one another, and allows you to use theinterface that suits you. A further strength of the X Windows system is that itis based on a client-server framework. This means that applications that are

    running can be thought of as clients to the X Server. Thus, an application canrun on one machine on a network, while displaying its output on anothermachine – making X Windows very well suited to a networked environment.

    Desktop environments take window managers a step further. Simplewindow managers cannot ensure a consistent look and feel across applications,nor can they handle cross-application data embedding. Desktop managersprovide a complete, integrated X Windows system. Two main desktops thatare freely available and widely used are the GNOME (GNU Network ObjectModel Environment) and the KDE (K Desktop Environment). As mentioned

    earlier, Ubuntu Linux uses the GNOME desktop. GNOME is also the defaultdesktop environment for the Debian and Fedora Linux distributions.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    15/133

     

    Linux Operating System | V1.0 Nov 2013 Page 11 of 133

    1. True or False: Linux is a Unix-based operating systemsuitable for personal computers.

    2. True or False: Linux is a multi-user operating system.

    3. True or False: The Linux kernel communicates directlywith the system hardware.

    4. In Linux, ____________ ensure a consistent look andfeel across applications and handle cross-application dataembedding.

    A. desktop managersB. window managersC. X Servers

    D. graphical shells

    5. Ubuntu is one of the many Linux _____________.

    A. X ServersB. window managersC. distributionsD. X Cores

    6. Linux is made up of the _____________, shell and

    utilities.

    A. coreB. kernelC. X WindowsD. File Manager

    7. Typically, the _____________ communicates betweenLinux and the computer’s hardware.

    A. X ServerB. AfterstepC. X WindowD. FVWM

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    16/133

     

    Linux Operating System | V1.0 Nov 2013 Page 12 of 133

    Unit 1 – Installing and Configuring Ubuntu 

    At the beginning of the module, you should have received an Ubuntu disc.This is a bootable Live CD. What this means is that you can boot from this CDwithout having to format your hard drive. There are two different boot options

    available when booting from an Ubuntu 12.04 Live CD:

    Boot Option 1When booting from the CD, the first screen to be displayed is a blank screenwith an icon towards the bottom middle of the screen (Figure 1.1). On thisscreen, you can press any key to be presented with a language selection.Select English, and from the next menu you have the option of trying Ubuntuwithout installing, installing Ubuntu, checking the CD for defects, testing thecomputer’s memory, and booting from the computer’s first hard disk. SelectTry Ubuntu without installing, which will present you with the Live CD

    desktop as shown in Figure 1.3.

    Figure 1.1 – Press any key

    At the end of this unit you will be able to:

    •  Install Ubuntu Linux from the Live CD.•  Set the screen resolution.

    •  Adjust the date and time.•  Change the appearance of the operating system.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    17/133

     

    Linux Operating System | V1.0 Nov 2013 Page 13 of 133

    Boot Option 2 When booting from the CD, do not  press any key when presented with thescreen in Figure 1.1. Instead wait a few seconds for the boot process tocontinue. Once it does, you will be presented with the Welcome screen shownin Figure 1.2. From here, click on Try Ubuntu  to proceed to the Live CD

    desktop as shown in Figure 1.3.

    Figure 1.2 – Welcome

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    18/133

     

    Linux Operating System | V1.0 Nov 2013 Page 14 of 133

    Once you have booted into the Live CD desktop, you can browse the Ubuntudesktop and familiarise yourself with the environment. Afterwards, if youchoose to, you can install the operating system by double-clicking on theInstall icon on the desktop. After answering a few simple questions, andfollowing a few easy instructions, the Ubuntu Operating System will be

    installed on your PC. If you choose not to, you can just remove the CD fromthe drive and restart your PC, after which you will boot into your normalinstallation.

    Figure 1.3 –Ubuntu Linux 12.04 Live CD desktop

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    19/133

     

    Linux Operating System | V1.0 Nov 2013 Page 15 of 133

    1.1 Installing Ubuntu 

    The first thing you need to do is to configure your CD/DVDdrive as your first boot device. This can be set up in the

    system’s BIOS. If you are unsure how to do this, ask yourlecturer for assistance.

    •  During startup, the computer will indicate that it is booting from the opticaldrive, and you can make use of the methods covered in either Boot Option1 or Boot Option 2 above to initiate the installation of Ubuntu.

    •  Having followed either of the above boot options and proceeded to Ubuntu’sLive CD desktop, and if you have finished exploring Ubuntu’s interface andmenus, double-click on the Install Ubuntu 12.04.2 LTS  icon on the LiveCD desktop to initiate the Ubuntu 12.04 installation (Figure 1.4).Alternatively, the following options for initiating Ubuntu 12.04’s installationwithout first booting into the Live CD desktop are also available:o  If you follow Boot Option 1, after pressing any key and making a

    language selection you can select the option to Install Ubuntu  toproceed directly to Ubuntu’s installation process.

    o  If you follow Boot Option 2, after waiting for the boot process toproceed and being presented with Ubuntu’s initial Welcome screen(Figure 1.2 above), select the option to Install Ubuntu.

    Figure 1.4 – Welcome screen

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    20/133

     

    Linux Operating System | V1.0 Nov 2013 Page 16 of 133

    •  The Installer will start up, and you will be presented with the Welcome screen, as shown in Figure 1.4 above. Here you need to select thelanguage that will be used for the installation process. Select English andclick Continue.

    • 

    This guide assumes that the computer you are installing Ubuntu on is not connected to the Internet. Therefore, on the Preparing to install Ubuntu screen (Figure 1.5), you can ignore the Internet connectionrecommendation and do not check the Download updates…  or Installthis third-party software and simply click Continue.

    Figure 1.5 – Preparing to install Ubuntu

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    21/133

     

    Linux Operating System | V1.0 Nov 2013 Page 17 of 133

    •  It is also assumed that you are installing Ubuntu on a computer that doesnot have any other operating systems installed, so on the Installationtype screen (Figure 1.6) select Erase disk and install Ubuntu and clickContinue.

    Should you be installing Ubuntu on a computer that already has anotheroperating system installed on it, select the option to erase and replace theexisting operating system with Ubuntu.

    Figure 1.6 – Installation type

    •  On the Erase disk and install Ubuntu screen, select the drive the Ubuntushould be installed to (if there is only one hard drive in your computer, itwill be selected by default) and click Install Now.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    22/133

     

    Linux Operating System | V1.0 Nov 2013 Page 18 of 133

    •  While Ubuntu copies its files and installs to your hard drive, the Where areyou? screen (Figure 1.7) will be displayed, asking you to select your city.Enter Johannesburg (or your city name) or click on the region on the maparound where your closest major city is. This will automatically select thecorrect time zone for that region, but you may have to manually set the

    correct date and time when you log in for the first time. Once you haveselected your region, and the installer has finished copying files, clickContinue.

    Figure 1.7 – Where are you?

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    23/133

     

    Linux Operating System | V1.0 Nov 2013 Page 19 of 133

    •  On the Keyboard layout screen (Figure 1.8), you are asked to select thecorrect keyboard layout. After you have selected the correct layout, youcan type in the provided box to test whether or not you have selected thecorrect layout. U.S. English is the standard layout. After you have selectedthe correct keyboard layout, click Continue.

    Figure 1.8 – Keyboard layout screen

    •  The Who are you?  screen (Figure 1.9) will now appear, where you areasked to fill in your name, a computer name, a username (your logon

    name) and a password. Fill in your own details. Be sure that you choose apassword that is easy to remember because you will be prompted to enterthis password in order to perform administrative tasks. Enter your detailsand click Continue.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    24/133

     

    Linux Operating System | V1.0 Nov 2013 Page 20 of 133

    Figure 1.9 – Who are you?

    •  Ubuntu will now proceed with its installation, displaying hints, tips andassorted information while it is busy. You can also continue browsing andexploring the Linux desktop and menus during the installation process.Once the installation has completed, you will be prompted to restart thecomputer. If you have finished exploring the system, click Restart Now.

    •  After selecting to restart the computer, you will be prompted to remove theinstallation media and press  to continue, after which the computer

    will finish restarting and boot into the Linux operating system.

    •  Once the computer has finished booting into the Linux operating system,you will be prompted to enter the password for the user that you specifiedduring installation.

    •  On your first login, an Update notification  message may appearprompting you to update the language files of the computer. For thepurposes of this guide, these updates are unnecessary and you can simplyclick Close.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    25/133

     

    Linux Operating System | V1.0 Nov 2013 Page 21 of 133

    1.2 Configuring Ubuntu 

    1.2.1  Setting the screen resolution

    To set the correct screen resolution, open the System menu by clicking on the

    cog icon on the far right of the top menu bar (note the options to log outand shut the computer down), and select Displays (Figure 1.10). Click on theResolution  drop-down box, and select the appropriate resolution for yourdisplay. 

    Figure 1.10 – Screen resolution preferences 

    NOTE The recommended resolutions for most 18.5” and 19” LCD/LEDmonitors are 1366 x 768 & 1440 x 900 respectively.

    1.2.2 

    Adjusting the date and time

    Click on the time displayed on the top menu bar and select Time & DateSettings to open the Time & Date screen. The Location box should displayJohannesburg, and beside the Set the time  section you can select theManually  radio button in order to set the correct time and date yourself.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    26/133

     

    Linux Operating System | V1.0 Nov 2013 Page 22 of 133

    Further options regarding the display of the time and date on the menu barcan be configured on the Clock tab. Changes are saved automatically, so onceyou have set the time and options, simply close the Time & Date screen byclicking on the orange X icon at the top left of the screen.

    1.2.3 Changing the appearance of the operating system

    In the Appearance page (Figure 1.11), you can change the Linux theme,desktop background, interface and visual effects. You can access this page inone of the following ways:

    •  By right-clicking on the Linux desktop and selecting Change DesktopBackground.

    •  By opening the System menu, clicking on System Settings, and selectingAppearance.

    Figure 1.11 – Appearance 

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    27/133

     

    Linux Operating System | V1.0 Nov 2013 Page 23 of 133

    Unit 2 – The Linux File System 

    2.1 The three main parts of the Linux file system 

    The Linux file system consists of three main parts:

    •  Superblock•  Inode area

    •  Data blocks

    Superblock  is used to control the whole file system. It contains static(unchanging) information on file system size, inode area size and logical datablock sizes. It also contains a partial list of free inode numbers and the firstfree data block of a chain of free blocks.

    Inode area is a set of blocks next to each other that contains a table listing allthe inode numbers for the file system. These numbers are used to track fileinformation within the file system. The main information kept for each fileincludes its file type, file permissions, number of links, owner and group, timestamps (date and time of last file change and access), file size and file locationon disk. The inode (short for index node) is the only control structure thatknows where to find a file’s data on the disk.

    Data blocks are where the actual file data is stored. Each block will contain

    data of only one file, although a file may reside in many blocks across the filesystem. Thus, the smallest disk space that can be allocated to a file is oneblock.

    2.2 

    File types 

    Table 2.1 lists the most common Linux file types.

    At the end of this unit you will be able to:

    •  Describe the three main parts of the Linux file system.•  Describe the common Linux file types.

    •  Understand the directory tree structure.•  Search for a file.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    28/133

     

    Linux Operating System | V1.0 Nov 2013 Page 24 of 133

    Table 2.1 – Linux file types

    Text files Normally contain configuration information.

    Directory files Files that serve as storage space to organise other

    files.

    Special device files Important files for systems administrators as they

    represent various system devices, e.g. hard drives

    and serial ports.

    Binary data files Program files are normally associated with several

    binary data files, which store information such as

    functions and graphics.

    Linked files Files that are associated with one another, i.e. they

    point to another file (shortcut file), or they can

    represent the same data.

    Executable program

    files

    These exist on the hard drive until they are executed

    in memory to become processes.

    Named pipes Identify the channel that passes information from one

    process in memory to another.

    Socket files A type of named pipe file that allows a process on

    another computer to write to a file on the local

    computer while another process reads from that file.

    2.3 File names 

    Files are recognised by their filenames, which can include up to 255characters. Linux filenames usually consist of alphanumeric characters,underscores ( _  ), dashes or hyphens ( -  ), and full stop characters ( . ).

    Besides a forward slash ( / ) and the null character, Linux technically has norestrictions on what characters may be used in a filename. However, it isadvisable to not use any shell metacharacters that are used in the command

    line prompt in a Linux terminal ( $,  # ) or to start a filename with a hyphen.Spaces in filenames are also typically discouraged.

    Files that begin with a dot ( .  ) are called hidden files, which require a special

    command to be seen (this command will be shown in Unit 4). The Linuxterminal will be discussed in the next unit.

    2.4 Directory files 

    The Linux file system has a completely different structure from that of theWindows file system. This unit will explain these differences to you, andexplain the structure of the Linux file system.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    29/133

     

    Linux Operating System | V1.0 Nov 2013 Page 25 of 133

    The main difference is that everything in the Linux file system is considered afile, i.e. devices, drives and removable media.

    The base of the file system is known as the root folder or ‘/’ (the equivalentof C:\ in Windows). The ‘/home’ folder stores each user’s files, i.e. settings,

    pictures, music, etc. (the equivalent of Documents and Settings\User inWindows).

    A directory  is a special file that contains a list of the files, paired with thosefiles’ inode numbers, stored in that directory. Every file in the Linux systemmust be in one or other directory. Directories have names like files, and thesenames follow the same conventions and rules used for file names. Everydirectory name must also be in a directory – this sets up the tree structure ofthe directory hierarchy. A directory that is found in another directory is calleda subdirectory.

    Table 2.2 shows the various Linux files.

    Table 2.2 – Linux files

    / bin Binary applications (the majority of executable files)

    / boot Files required to boot, e.g. the kernel

    / dev Devices, e.g. drives and displays

    / etc Almost every configuration file for the system

    / home User files and folders that are stored locally

    / lib System libraries (equivalent of Program Files in Windows).

    In a 64-bit installation of Linux, a /lib64 directory will also

    be present.

    / lost + found The lost and found for lost files

    / media Mounted devices, e.g. CD-ROMs, digital cameras and flash

    disks

    / mnt Mounted file system

    / opt The location for optionally installed programs

    / proc A dynamic directory that holds the information for processes/ root The root user’s home folder

    / sbin System-only binaries

    / sys Holds system information

    / tmp Temporary files

    / usr Applications for regular users

    / var Holds logs, databases, etc.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    30/133

     

    Linux Operating System | V1.0 Nov 2013 Page 26 of 133

    2.5 The directory structure 

    Figure 2.1 – ‘Tree’ structure 

    Figure 2.1 depicts the Linux directory structure. The root  directory (alsocalled the root) contains a list of ordinary and directory files. The root is themain directory under which all other directories are found. Figure 2.1 showssome of Linux’s standard subdirectories.

    Each of these standard subdirectories is created for a specific purpose. Forexample, the bin subdirectory contains the executable files of mostapplications, the tmp  subdirectory is used to store temporary files, and thehome subdirectory file is a list of user directories. Figure 2.1 also shows the

    usr  subdirectory, which is a directory that contains all users’ program andapplication files, as well as the accompanying documentation for thoseprograms. In this way, Linux and its users keep control of their files in ahierarchical tree structure.

    You will also notice in Figure 2.1 that one of Linux’s standard subdirectories iscalled root. This root subdirectory is actually the home directory of a specialuser called root. When an administrator logs in to make system changes thatonly an administrator is allowed to make, the administrator will log in with theuser name root. The root user, also known as the superuser, is given all

    system privileges and that is why the root user account is used by theadministrator to maintain the system.

    Whenever you encounter the term root in Linux, make sure you understandwhether it refers to the root directory, the root subdirectory or the root user.

    When considering Linux files, you should keep three factors in mind:

    •  The file is stored physically on disk in data blocks.

    •  Each file is described by an inode number that contains all the informationabout a file except its name. Every file has only one inode numberassociated with it. The root  directory has the inode number 1, and allothers are incremental from that point.

    BIN BOOT 

    ETC  USR VAR SBIN TMP DEV HOME

     / ‘ROOT’

    LIB MNT OPT

    USERS CD ROMTMPSYSCONFIG

    ROOT

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    31/133

     

    Linux Operating System | V1.0 Nov 2013 Page 27 of 133

    •  Each file name is contained in a directory that contains the file name andinode number.

    Every file’s pathname identifies the file’s location within the directoryhierarchy. A pathname is really a list of one or more file names (directories)

    that point to the file.

    •  Every file has one absolute pathname that identifies that file uniquely. Thisabsolute pathname begins with the root directory, and follows the uniquepath through the subdirectories that point to a particular file. For example,a file located in the SQL_demo  directory called my file  would have theabsolute pathname:

    /home/user_1/SQL_demo/my_file

    • 

    A shorter relative pathname (or partial pathname) can be used that beginswith the current directory, and describes the path to the required file fromthere. If you were in the user_1 directory, the relative pathname for myfile would be:

    SQL_demo/my_file

    •  The easiest way to distinguish between absolute and relative pathnames isthat absolute pathnames always begin with the root directory.

    •  Notice that directories are separated in the pathname by forward slashes

    , not backward slashes as in Windows.•  The current directory is represented by a single dot.

    •  The parent directory (the directory immediately above the current directoryin the hierarchy) is represented by two dots.

    NOTE Your home directory will be /home/your username. When youlog on to the system, this is the directory that you will be in.

    2.6 Searching for files 

    The GNOME desktop provides the Search for Files tool for finding files andfolders in the Linux file system. The Search for Files tool enables the user tosearch for files at or below a certain level in the file hierarchy. The startingpoint for the search is specified in the Look in folder: field (Figure 2.2). Onlyfiles in or below the specified folder will be searched. To search all files andfolders on the Linux system, the root directory must be specified as thestarting point for the search. If the file being sought is known to be in aparticular folder, then that folder may be specified as the starting point for thesearch to limit the number of search results.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    32/133

     

    Linux Operating System | V1.0 Nov 2013 Page 28 of 133

    Figure 2.2 – Search for files

     

    Open the File Manager by clicking on the Home icon on thesidebar.

    •  Click on the Search  button on the top right of the FileManager window to reveal the search bar.

    •  Search for a file called resolv.conf  and note the folder thatcontains this file (you may need to modify the location thatis being searched).

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    33/133

     

    Linux Operating System | V1.0 Nov 2013 Page 29 of 133

    1. True or False: Linux directory names follow the sameconventions and rules used for file names.

    2. True or False: A pathname is really a list of one or morefile names (directories) that point to the file.

    3. True or False: Directory files contain only the inodenumbers of the files within them.

    4. Which one of the following is not  contained in thesuperblock of the Linux file system?

    A. Listing of inode numbers.B. Inode area size.C. File system size.

    D. First free data block.

    5. In the Linux file system, data is stored and organisedby being placed in _____________ that are kept on astorage device such as a hard disk.

    A. program filesB. executable filesC. directory filesD. ordinary files

    6. Which one of the following is not  a valid file name inLinux?

    A. .val_1-99B. file_12.memC. today file 12/06/03D. a.valid.name

    7. If the current directory is the home directory, and auser wants to refer to the password file in the etc directory, which one of the following would be the correctabsolute pathname to use?

    A. etc/passwdB. ././etc/passwdC. /etc/passwdD. ../../etc/passwd

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    34/133

     

    Linux Operating System | V1.0 Nov 2013 Page 30 of 133

    Unit 3 – The Linux Terminal 

    The Graphical User Interface (GUI) is only one way of interacting with theLinux operating system. A more direct and powerful way of communicatingwith the Linux system is by using a command line interpreter. You can access

    a Linux command line interpreter from the Linux desktop by opening a Linuxterminal window.

    3.1 Terminal basics 

    •  Opening a Linux terminal window.

    •  Configuring keyboard shortcuts.•  Configuring user preferences.

    3.1.1 Opening a Linux terminal window

    On the sidebar, click on Dash home  to open the Dash overlay. Select theTerminal application or, if the Terminal application is not visible on the frontDash screen, enter terminal in the Dash search bar and select the Terminal application from the search results.

    3.1.2 Configuring keyboard shortcuts

    A quicker way to open a terminal is to add a keyboard shortcut. On theKeyboard Shortcuts page (Figure 3.1) you can configure shortcuts for almostevery application, e.g. starting the calculator, resizing windows, launching youremail and Internet applications, and even adjusting your sound preferences.

    To add a keyboard shortcut to run a terminal: Open the System Settings,either via the System menu on the top menu bar or via the System Settings icon on the sidebar, and click on Keyboard. Select the Shortcuts tab, thenselect Launchers from the list on the left hand side.

    At the end of this unit you will be able to:

    •  Open a Linux terminal window.•  Configure keyboard shortcuts.

    •  Configure user preferences.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    35/133

     

    Linux Operating System | V1.0 Nov 2013 Page 31 of 133

    Now select Launch Terminal from the list on the right hand side and type inyour preferred key combination (note that New accelerator  is displayed onthe far right to indicate that the system is waiting for you to supply a keycombination), e.g. . Exit the page, and press the shortcut that youspecified. This will then open a Linux terminal (Figure 3.2).

    Figure 3.1 – Configuring keyboard shortcuts 

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    36/133

     

    Linux Operating System | V1.0 Nov 2013 Page 32 of 133

    Figure 3.2 – Example of a Linux terminal

    3.1.3 

    Configuring user preferencesWith the terminal window open, hover the mouse pointer over the left handside of the top menu bar to reveal the menu options for the terminal window.Select the Edit  menu, and select Profiles. You can either use the defaultprofile, or create an additional one (Figure 3.3). Select the default profile andclick Edit.

    •  Set profile name, and options for font, cursor and terminal bell on theGeneral tab.

    •  Set window title and exit options on the Title and Command tab.

    • 

    Set theme or background and foreground colours on the Colors tab.•  Set background options on the Background tab.

    •  Set scroll bar options on the Scrolling tab.•  Set keyboard compatibility on the Compatibility tab.

    •  Click the Close button to apply the new settings and exit the dialog box.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    37/133

     

    Linux Operating System | V1.0 Nov 2013 Page 33 of 133

    Figure 3.3 – Terminal preferences

    3.2 

    The Linux prompt 

    The command prompt shows that Linux is ready for you to enter a command.

    When you open the command console, you should see a command line promptthat looks something like this:

    [user_name@computer_name]:~$

    •  user_name  is the name you will use to log into Linux. If you are using astandalone Linux installation, you will specify your user_name duringinstallation or by adding yourself as a user. If you are accessing Linux on anetwork, your user_name will be allocated to you by the networkadministrator.

    •  computer_name is the name of the Linux box (machine) to which you arelogged on.

    •  The ~ symbol identifies the directory that the terminal is currently in, withthe tilde (~) symbol indicating that the terminal is currently operating in thelogged-on user’s home directory. This symbol will change to reflect thedirectory being operated in when the directory is changed.

    •  The $ symbol is the default prompt of the bash shell, but will vary accordingto the shell you are using.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    38/133

     

    Linux Operating System | V1.0 Nov 2013 Page 34 of 133

    3.3 

    System identification 

    Where Linux is being accessed via a network, the network administratorassigns each user a unique identification number associated with the user’slogin name. Users are also allocated to a group (or groups). These groupsusually represent a set of users with similar needs, such as members of adepartment or a team working on a particular project.

    The User ID (UID) and Group ID (GID) are used to enforce file ownership,permissions and other security measures within the Linux system.

    As discussed in section 2.4, Linux has a special privileged account with thename of root that is used by the administrator to maintain the Linux systembecause root is given all system privileges. The root account has a UID ofzero.

    The user that you created during the installation process (yourself) hasautomatic administrative rights on the machine. You are, however, required toadd the sudo prefix to commands to be able to perform most administrativetasks. Sudo  is a Linux program that allows users to run programs with thesame privileges as the root user (essentially allowing a user to run a commandas root). Users can be given these privileges by editing the /etc/sudoers file. When users attempt to perform administrative tasks using sudo, they willbe prompted to enter their password (this was also mentioned during theinstallation process).

    In the next exercise, you will create an additional user, Mordin, and manipulatehis and your own passwords on the Linux system. He will not be part of thesudoers group, and will not have permission to perform any administrativetasks.

    •  Change user passwords.

    •  Add a normal user (Figure 3.4).

    •  The passwd command is used to change users’ passwords. To change your

    own password, enter the following command and follow the prompts:

    passwd

    •  At the Linux prompt, type:

    sudo adduser mor di n

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    39/133

     

    Linux Operating System | V1.0 Nov 2013 Page 35 of 133

    •  When prompted, enter your password. The user will be created, and youare required to enter a password and other information for the new user(Figure 3.4).

    •  Confirm that the user information is correct.

    Figure 3.4 – Adding a user 

    •  To change the passwords of other users, such as mordin, enter the

    following command and follow the prompts:

    sudo passwd mor di n

    •  To configure a password for the root user, use the passwd command withroot privileges:

    sudo passwd

    •  Close the terminal. Click on the Quit button on the top left hand corner

    (hover the mouse point over the left hand side of the top bar to reveal thebutton) or, alternatively, enter the exi t  command to quit the terminal, and

    log out of Linux.

    •  At the log in screen, log in as mordin using the information that you enteredin the previous steps.

    •  Once logged in, open a new terminal and type the following command:

    sudo adduser genophage

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    40/133

     

    Linux Operating System | V1.0 Nov 2013 Page 36 of 133

    •  The prompt will respond to the command with the following warning (Figure3.5):

    mordin is not in the sudoers file. This incident will be reported 

    Figure 3.5 – This incident will be reported 

    •  Log out of Linux, and log back in with your own account.

    3.4 

    Linux command syntax 

    When working in the Linux terminal or using command interpreter shells, auser communicates with the operating system by using various commands, inmuch the same way as using other command line interpreters, such as MS-DOS.

    The command console or shell interprets Linux commands and directs thekernel to carry out the user’s request. Each command line is made up of oneor more distinct elements, known as the command syntax. The general formatof a Linux command is:

    $ command [options…] [arguments…]

    •  The first part is the command itself.•  There may be options that modify the behaviour of the command.

    •  The arguments  are character strings that are passed to the command,providing extra information such as file names.

    •  The square brackets indicate that the options and arguments are optional.The ellipses indicate that one or more options or arguments may beprovided.

    • 

    Whitespace characters separate the various elements of a command.Generally, only one space is inserted using the .

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    41/133

     

    Linux Operating System | V1.0 Nov 2013 Page 37 of 133

    3.4.1 Entering commands

    •  Linux is a case-sensitive operating system. It recognises the differencebetween uppercase and lowercase characters. Consequently, Pictures  isnot the same file as pictures, and MUSIC is not the same file as music.

    •  Commands are generally entered in lowercase, but some commands and

    options use uppercase characters.•  If a command is typed incorrectly or not found, Linux will respond with the

    message:

    command: command not found

    •  Pressing the   key sends commands to be processed. Commandsmust be in their correct form before pressing .

    •  The  key can be used to delete any incorrect characters.

    •  Pressing  will discard whatever has been typed on the current

    input line, leaving a new blank line to restart the command.•  Press  to continue a command on a new line if the command is

    too long to fit on one line. The backslash character  (called an escapecharacter) tells Linux that the following character is to be interpreted literallyand not in the usual way. Pressing  provides a new line onwhich to continue typing a command. Linux ignores the usual use of and the command is not sent for processing.

    •  Use the semicolon   to separate commands so that more than onecommand can be entered on a single line.

    •  Press  to clear the screen.

    • 

    Press the up and down cursor keys to move up and down the list ofpreviously entered commands.

    •  Commands are remembered in the terminal even when you log out of Linux.

    The hi stor y  command can be used to view a history of the commands

    entered into the terminal, which hi st or y –c  can be used to clear the

    command history.

    •  Linux offers tab line completion. Begin typing a command and then pressthe  key to complete the command automatically.

    •  Use   and   to move up anddown previously displayed screens.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    42/133

     

    Linux Operating System | V1.0 Nov 2013 Page 38 of 133

    3.4.2 

    Basic Linux commands

    Now that you know the basic syntax of a Linux command, howto enter commands, and how to move around the commandconsole, it is time to try some Linux commands for yourself.

    For this section, it is strongly advised that you try each of thecommands in a Linux terminal window.

    To see how you are identified on the system:

    •  Type whoami  at the prompt and press . 

    To see the UID and GID, and membership of other groups:

    •  Type i d at the prompt and press . 

    To view all system information:

    •  Type uname –a at the prompt and press . 

    Using the uname - a command will produce output similar to the following:

    Linux host 2.2.14-5.0 #1 Tue Mar 7 21:07:39 EST 2000 i686 unknown

    Linux The operating system being used

    host The Linux box’s name

    2.2.14-5.0 The kernel release

    #1 Tue Mar 7 21:07:39 EST

    2000

    The operating system version and

    the date and time that the kernel

    release was compiled

    i686 The type of machine (i686 is a

    Pentium II)

    unknown The processor, which may be

    unknown

    To display a list of users currently logged on to the system:

    •  Type who at the prompt and press .

    This command will tell you who is logged on (user names), which terminalsthey are using, and the dates and times when they logged on.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    43/133

     

    Linux Operating System | V1.0 Nov 2013 Page 39 of 133

    To find out more information about the users that are logged on:

    •  Type w at the prompt and press .

    The w command will display:

    o  The current time.

    o  How long the system has been up and running (the system’s uptime).

    o  How many users are currently logged on.

    o  The system load averages for the past one, five and fifteen minutes.

    o  For each user: user name, terminal name, remote host, login time, idletime, JCPU (time used by all processes attached to the terminal), PCPU(time used by the current process [named in the what field]), and thecurrent process.

    Figure 3.6 – Basic Linux commands

    To display the current date and time:

    •  Type date at the prompt and press .

    (SAST in the output stands for South African Standard Time.)

    To clear the screen:

    •  Type cl ear  at the prompt and press .

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    44/133

     

    Linux Operating System | V1.0 Nov 2013 Page 40 of 133

    To display text to the screen:

    •  Type echo Br i ngi ng t he spi r i t of Ubunt u t o t he sof t war e wor l d at

    the prompt and press .

    This command can be used to sound the system bell using the escapecharacter  \a. To echo any part of the text on a new line, precede that textwith the escape character \n. To use escape characters, surround the textwith inverted commas and add the -e option. For example:

    echo - e “\ aThi s wi l l sound t he syst em bel l ”echo –e “Thi s t ext wi l l be di spl ayed on \ nt wo di f f er ent l i nes”

    Figure 3.7 – The echo command 

    •  Clear the screen using both the command and the shortcutkey combination.

    •  Display the message Hello there on the screen so that thesystem bell sounds and each word is displayed on aseparate line.

    To display a calendar for the current month:

    •  Type cal  at the prompt and press .

    To display a calendar for the current year:

    •  Type cal - y at the prompt and press .

    To display a calendar for the year 2014:

    • 

    Type cal 2014 at the prompt and press .

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    45/133

     

    Linux Operating System | V1.0 Nov 2013 Page 41 of 133

    When specifying the year, use the full year. For example, type 1995, not 95.Values can range from 1 - 9999.

    To display a calendar for the month of December in the year 2013:

    • 

    Type cal 12 2013 at the prompt and press .

    When specifying the month and the year, type the number for the month first(1 - 12). By default, Sunday is displayed as the first day of the week. Todisplay Monday as the first day of the week, use the -m option. For example,cal 2 1995 –m will display February 1995, with Monday as the first day of theweek.

    •  Use the cal  command to find out on what day of the week

    you were born.

    • 

    Use a semicolon to combine the date and  who commands totype them on a single command line.

    To shut down Linux immediately:

    •  Type sudo shutdown –h now at the prompt and press .

    The shutdown command:

    •  Has the following syntax: shutdown options time message.

    •  Uses the –r   option to reboot the machine and the –h  option to halt the

    system.

    •  Can be used to shut down the system in a specified number of minutes.

    •  Uses the word ‘now’ instead of ‘mi nut es’ for immediate shutdown.

    •  Use the shutdown  command to halt the machine in three

    minutes’ time, informing all users that the system will berestored in ten minutes’ time.

    3.5 Getting help 

    You can use the man (manual) command to get help about any Linux

    command. The man command will provide details on the use of the command,

    including:

    •  Correct syntax.•  Description (uses of the command).

    • 

    Examples (how the command can be used).•  See also (cross references to related commands).

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    46/133

     

    Linux Operating System | V1.0 Nov 2013 Page 42 of 133

    To view more information on the sudo command:

    •  Type man sudo at the prompt and press .

    To exit the help pages and return to the command prompt:

    •  Press the button on the keyboard.

    •  Make a note of the various options that can be used with the

    shutdown  command. Use the man command to display this

    information.•  Make a note of the various options that can be used with the

    who  command. Use the man  command to display this

    information.

    •  Use the options - H, - I , and - q with the who command and

    observe the effect of each option. Experiment with using thecommands in combination. For example, try the following:

    who –H and who - u.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    47/133

     

    Linux Operating System | V1.0 Nov 2013 Page 43 of 133

    1. True or False: The User ID and Group ID are used toenforce file ownership, permissions and other securitymeasures within the Linux system.

    2. The command that can be used by a user to change his or

    her own password or by root to specify a password for auser on the Linux system is ________.

    A. pwd 

    B. user pwd 

    C. passwd 

    D. passwor d 

    3. True or False: In Linux commands, arguments areoptional.

    4. The general format of a Linux command is: ____________.

    A. $ command [options…] [arguments…]B. $ command [options…]C. $ command [arguments]D. $ command [arguments…] [options…]

    5. ____________ refers to the proper structure of a

    command.

    6. A ____________ tells the system what action to perform.

    7. A command ___________ modifies the behaviour of acommand.

    8. A command ___________ provides further informationfor a command.

    9. Which Linux command will display information such ashow long the system has been running and how many usersare currently logged on?

    A. who - a 

    B. w 

    C. sys 

    D. usrs  

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    48/133

     

    Linux Operating System | V1.0 Nov 2013 Page 44 of 133

    Unit 4 – Working with Directories 

    4.1 Directory commands 

    In a Linux terminal, there are several useful commands that you can enter atthe command prompt to work with Linux directories. For example: 

    To display the pathname of the present working directory:

    •  Type pwd at the prompt and press . 

    To display a list of files in the current directory:

    • 

    Type l s at the prompt and press .

    Table 4.1 – Directory listing options

    -la long listing – displays permissions, number of links, owner, group, file size,

    modification date and time, and file name (sorted by file name).

    -hwhen used with -l, displays the file size in a format that can be read by

    humans.

    -a list of all files, including hidden files (beginning with . dot. ).

    -i list of file names with inode numbers in the first column.

    -Cmulticolumn format, file names in columns down the screen (same as the

    default command without options).

    -cmulticolumn format, file names in columns down the screen with directories

    listed first.

    -x multicolumn format, file names in rows across the screen.

    -R recursive listing of all files, subdirectories included (i.e. full directory listing).

    -Fshows file types (forward slashes identifying directories and asterisks

    identifying executable files).-1 (the number 1) displays files in a single column down the screen.

    At the end of this unit you will be able to:

    •  Display the pathname of the present working directory.•  List the files in the current directory.

    •  Create a new directory.•  Change the current directory.

    •  Delete directories and their contents.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    49/133

     

    Linux Operating System | V1.0 Nov 2013 Page 45 of 133

    •  Identify your present working (current) directory.

    •  Experiment with the various options of the  l s 

    command.

    To create a new directory:

    •  Type mkdi r directory_name at the prompt and press .

    •  Create a new directory called Projects.

    To change to a specified directory:

    •  Type cd speci f i ed_di r ectory at the prompt and press .

    •  Change to the newly created Projects directory.

    •  Note that the prompt changes to indicate that Projects  isthe current directory.

    •  Confirm that you have changed to the Projects directory by

    using the correct command to check the present workingdirectory.

    •  Get a directory listing to show all files.•  Note that the new directory is empty except for the dot .

    (current) and dot, dot .. (parent) directories.

    To return to your home directory:

    •  Type cd at the prompt and press .

    To change to the parent directory of the current directory:

    •  Type cd . .  at the prompt and press .

    In some of the exercises that follow, you will have to create certain files using

    the t ouch command. The t ouch command will be covered in more detail in

    Unit 5. For now, all you have to know is how to create an empty file with thespecified file name.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    50/133

     

    Linux Operating System | V1.0 Nov 2013 Page 46 of 133

    To create and name an empty file using the touch command: 

    •  Type t ouch f i l e_name and press .

    To delete everything in the current directory:

    •  Ensure that you are in the directory that you want to empty and type r m *  

    and press .

    •  Ensure that you are in your home directory.

    •  Create a new directory called practice2.•  Change to the practice2 directory.

    •  Create file1 and file2 using the t ouch command.

    •  Get a listing to confirm that they exist.

    •  Delete all files in the practice2 directory using r m * .  

    • 

    Get a listing to confirm that all the files have been deleted.

    To delete everything in the current directory and everything below it inthe subdirectory hierarchy:

    •  Ensure that you are in the directory that you want to empty and at the top

    of the tree you want to erase, and type r m – r * and press .

    •  Ensure that you are in the practice2 directory.

    •  Create a file called file1 using the t ouch command.

    • 

    Create a subdirectory called sub.•  Change to the sub directory.

    •  Create a file called file2 using the t ouch command.

    •  Change to the practice2 directory using parent directorynotation.

    •  Delete file2, the sub  directory, and file1  using a singlecommand.

    •  Do a listing to confirm that the sub directory and both fileshave been deleted.

    To delete a directory:

    •  Ensure that the directory you want to delete is empty, and that you are not

    in the directory you want to delete. Type r mdi r di r ectory_name and press

    .

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    51/133

     

    Linux Operating System | V1.0 Nov 2013 Page 47 of 133

    •  Ensure that the practice2 directory is empty.

    •  Change to your home directory.

    •  Delete the practice2 directory using the r mdi r  command.

    To delete a directory and all of its contents:

    •  Ensure that you are not in the directory that you want to delete, and type

    r m –r di r ect or y_name and press .

    •  Create a directory called practice3.

    •  Change to the practice3 directory.

    •  Create file1 using the t ouch command.

    •  Change to your home directory.

     

    Delete the practice3 directory and its contents using the r m–r  command.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    52/133

     

    Linux Operating System | V1.0 Nov 2013 Page 48 of 133

    1. Which Linux command will display the current workingdirectory?

    A. pwd 

    B. l s 

    C. l s - a D. di r  

    2. Give the Linux command that will display a list of files in thecurrent directory along with their inode numbers.

    3. Give the Linux command to display a list of all files in thecurrent directory, including hidden files.

    4. Give the Linux command to create a subdirectory called

    mysub in the current directory.

    5. Which Linux command can be used to delete a directory andall its contents?

    A. r m - r  

    B. rd -a 

    C. r mdi r - r  

    D. r dd - a

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    53/133

     

    Linux Operating System | V1.0 Nov 2013 Page 49 of 133

    Unit 5 – Working with Files 

    5.1 Basic Linux file commands 

    In Unit 4, you used the touch command to create empty files with specifiednames. The same command can be used to change the time stamp of a file.

    To change the time stamp of a file without changing its contents:

    •  Type t ouch f i l e_name and press .

    The t ouch command:

    •  Will create a new, empty file if the file name specified does not already exist.

    •  Updates the last accessed time for the file.

    •  Does not open the file in a text editor (as the vi  command would).

    •  Is particularly useful for updating the time stamp of a file that relies on date-related activities such as archiving and backing up.

    •  Create a new, empty file called Reports.file.

    •  Get a listing to check that the file exists, and note the file

    size.

    To display the type of a file:

    •  Type f i l e f i l e_name and press .

    To display the file types of all files in the current directory:

    •  Type f i l e * and press .

    At the end of this unit you will be able to:

    •  Change the time stamp of a file.•  List files with their file types showing.

    •  View the contents of files.•  Search files for specific text patterns.

    •  Display the differences between two files.•  Copy, move and delete files.

    •  Change file ownership and file permissions.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    54/133

     

    Linux Operating System | V1.0 Nov 2013 Page 50 of 133

    The f i l e command:

    •  Is useful for getting a quick idea of the nature of a file’s contents.

    •  Performs a series of tests on the file(s) specified in an attempt to report aclassification; sometimes the file type reported will be unfamiliar.

    •  Display the file types for all files in the current directory

    5.2 Creating a simple text file 

    5.2.1 Text editorsA text editor is a program that can be used to create and modify the contentsof a file. In this module, you will work with one of Ubuntu’s built-in texteditors, vi (pronounced vee-eye).

    Technically, vi in Ubuntu 12.04 is actually vim-tiny. Vim (Vi IMproved) is anupdate of the older vi, while vim-tiny  is a smaller version of vim. Despitethis, the vi  command is still used to launch the editor. Another of Ubuntu’sbuilt-in text editors is nano.

    A text editor is a very simple version of a word processor. Text editors do nothave document formatting features, such as various fonts and ways of aligningtext. Text editors produce simple text files.

    The visual editor, vi, runs in two modes:

    •  Command mode – This is the mode you enter automatically when you startvi. Whatever you type in this mode will be interpreted as an editingcommand, such as copy, paste and delete text. You can also save and exitthe file from within this mode.

     

    Text entry mode – This mode is used to enter text. Keys pressed in thismode are interpreted as characters, and are inserted into the text file.

    Pressing , ,  or  will take you from command mode into textentry mode. The command you choose to enter the text entry mode dependson what you intend to do. For example, choose   to insert text at thecurrent cursor position. The other options will be discussed in the text entrymode section.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    55/133

     

    Linux Operating System | V1.0 Nov 2013 Page 51 of 133

    5.2.2 

    Text entry mode

    To add text to a file in vi, you need to be in text entry mode. As discussed insection 5.2.1, there are several commands for entering the vi text entry mode.Choose the command to enter the text entry mode according to what youintend doing. The main commands and their uses are as follows:

    Table 5.1 – Text entry mode commands

    a Appends (adds) text immediately after the cursor.

     A Appends text at the end of the current line.

    i Inserts text at the current cursor position.

    I Inserts text at the start of the current line.

    C Inserts new text from the cursor to the end of the current line.

    o Opens a line below the current line and places the cursor at the start ofthe new line.

    O Opens a line above the current line and places the cursor at the start of

    the new line.

    s Overwrites the character or selected text at the current cursor position,

    and inserts subsequent text.

    •  Create a new text file called Ubuntu using vi (i.e. vi

    Ubunt u).

    • 

    Type the verses below into the buffer, using the key at the end of each line, and the  key todelete mistakes. Once you have entered the text below,leave the file open and continue with the next section.

    Umunt u ngumunt u ngabant uHumani t y t o ot hersI am what I am because of who we al l ar e

     The Ubunt u Li nux di st r i but i on ai ms

     To br i ng t he spi r i t of Ubunt u t o t he sof t war e wor l d 

    5.2.3 Command mode

    To issue a command in vi , you must be in command mode. When you open

    vi , you will be in command mode by default.

    To return to vi command mode from text-entry mode: 

    •  Press the  key.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    56/133

     

    Linux Operating System | V1.0 Nov 2013 Page 52 of 133

    The first vi  command we are going to look at is , which provides a

    status line at the bottom of the screen. It shows the file name, whether it is anew file and whether it has been modified, the current line number and thenumber of lines, and an indication of how far into the file you are (given as apercentage).

    Next, we will look at the vi  commands for saving and exiting files. These are

    as follows:

    •  : w  save your changes to disk; you remain in the vi  editor.

    •  : q!   abandon your changes and return to the command line prompt.

    •  : q  exit vi, and return to the command prompt (when no changes were

    made).

    •  : wq 

    •  : x  save changes, and return to the command prompt.

    • 

    ZZ

    Save all changes to the Ubuntu  file and return to thecommand prompt. Use the colon with the letter/symbol.

    NOTE You will have to press after all save and exit commands,

    except ZZ. Typing ZZ  in command mode will immediately save

    changes to the file and return to the command line prompt(remember that Linux is case-sensitive). If you start vi without

    entering a file name, you will need to specify a file name when yousave it. The format is as follows:

    : w filename. This syntax will also work with : wq and : x.

    5.3 Viewing files 

    To view the contents of a file: 

    •  Type cat f i l e_name and press .

    The cat  (concatenate) command:

    •  Is a quick command to display the contents of a file on the screen.

    •  Does not allow you to move backwards and forwards in the file and, if thecontents cannot fit onto one screen, the display will scroll to the end of thefile.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    57/133

     

    Linux Operating System | V1.0 Nov 2013 Page 53 of 133

    •  Use the cat  command to view the contents of the Ubuntu 

    file.

    To view the contents of a file in controlled amounts: 

    •  Type more f i l e_name and press .

    To view the contents of a file from a specific file number: 

    •  Type more +l i ne_number f i l e_name and press .

    (For example: mor e +2 Ubunt u  to view the contents of the Ubuntu  file

    from line two.)

    After entering the mor e  command, the first part of the file scrolls up thescreen. At the bottom of the screen, a prompt displays the file name and thepercentage of the file displayed so far. Note that this percentage is incharacters, not lines. At this point, there are several commands that may beused, depending on how you want to proceed:

    Table 5.2 – The more command options

    Displays the next full screen.

    n   Displays n more lines.

      Moves down one more line of text.

     or

     

    Moves back one full screen.

     or Quits (exits) from more  and returns to the command

    prompt.

     or Displays a list of all the more commands.

    •  Use the mor e command to view the Ubuntu file.

    • 

    Experiment with the various display options available withinthe more command.

    To view the contents of the file and be able to move around in the file: 

    •  Type l ess f i l e_name and press .

    The l ess  command is similar to the mor e  command, but allows greater

    flexibility in moving backwards and forwards in a file.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    58/133

     

    Linux Operating System | V1.0 Nov 2013 Page 54 of 133

    Table 5.3 – The less command options

    Move to the top of the file.

    Move to the end of the file.

      and   Move up and down one line at a time.

     or   Display help.

     or   Quits (exits) from less and returns to the command prompt.

    •  Use the l ess command to view the Ubuntu file.

    •  Experiment with the various display options available with

    the l ess command.

    To display the first ten lines of a specified file:

    •  Type head f i l e_name and press .

    To display the first n lines of a specified file:

    •  Type head –n f i l e_name and press .

    To display the last ten lines of a specified file:

     

    Type t ai l f i l e_name and press .

    To display the last n lines of a specified file:

    •  Type t ai l –n f i l e_name and press .

    To display the end of a file from the nth line:

    •  Type t ai l +n f i l e_name and press .

    • 

    Use the head and t ai l  commands to view the Ubuntu file.•  Try the following commands and compare the results:

    head Ubuntu

    o  head - 2 Ubunt u

    t ai l +2 Ubunt u

    o  t ai l –5 Ubunt u

    t ai l Ubunt u

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    59/133

     

    Linux Operating System | V1.0 Nov 2013 Page 55 of 133

    To count the number of lines, words and characters in a specified file: 

    •  Type wc [ opt i ons] f i l e_name and press . 

    Table 5.4 – The wc command options

    -l Line count

    -w Word count

    -m Character count

    •  Use the wc command to get information on the Ubuntu file.

    Try the following commands and compare the results:

    o  wc Ubunt u

    wc – l –w –c Ubuntu

    wc – l –m Ubunt u

    o  wc –w –m Ubunt u

    wc –l w Ubunt u

    To sort the contents of a file into alphabetical or numerical order:

    •  Type sort  f i l e_name and press .

    The sort  command:

    •  Outputs the sorted file to the screen, but does not modify the original file.•  Uses each new line as a new record.

    •  Will sort according to alphabetical or numerical order, depending on filecontent.

    •  Has several options not covered in this module.

    •  Create a new file called people, using the vi   editor and

    type Kaidan, Garrus, James, Thane, Legion and Liara – eachon a different line.

    •  Save the file.•  Sort the contents of the people file into alphabetical order,

    using the sort command.

    •  Use the man command to find out how to sort in ascending

    and descending order.

  • 8/17/2019 Linux Operating System Interactive Study Guide - ULNXC-14 V1.0

    60/133

     

    Linux Operating System | V1.0 Nov 2013 Page 56 of 133

    To search files for a specific pattern or text:

    •  Type gr ep [ opt i ons] expr essi on f i l e_name and press . 

    The gr ep command:

    •  Is a quick way to search a file for a string pattern.•  Allows you to search all files for a specific text string.

    •  Requires the search phrase to be placed in single quotes.•  Displays the line of text containing the specified text string.

    •  Will not find text patterns spread over more than one line.

    Table 5.5 – The grep command options

    -c displays only the number of matching lines in each file.

    -l lists only the name of the file that contains the specified pattern (stops

    scanning after first match is made).

    -n displays the line number of the line containing the specified text.

    -i does not distinguish between uppercase and lowercase.

    •  Use the gr ep�