Coventry University Logo
4061CEM - Programming and Algorithms 1

Introducing…

Virtual Machines and Linux

Dr Ian Cornelius

Hello

  • Learning Outcomes:
    1. Understand the purpose of virtual machines and their use-case in this module
    2. Understand the various Linux commands that will be useful for this course and module
    3. Demonstrate your knowledge using Linux and the various commands in the lab activities and projects

Introduction to Virtual Machines

  • Virtual Machines (VM) are a software representation of a computer
    • enable you to run applications as if they are on a physical machine
  • Provides an interface to the underlying hardware of the local machine
  • Creates a sandbox environment for testing malicious applications or code
  • Advantages:
    • Variety of different operating systems can run separately with its own resources
    • Adding and removal extra resources is easy
  • Disadvantages:
    • Enabling direct access to the hardware can be quite difficult
    • Large amounts of memory and disk-usage is utilised
    • In some cases it can be less efficient than running an actual machine

Virtual Machine Software

  • Two types of software available:
    1. Free-ware
    2. Pay-ware
  • Various options are available for different operating systems
    • there is no best software, use the one that you prefer

VMWare Workstation Pro

  • Payware Application
  • Available for Linux and Windows
  • Download: Accessible Here

VMWare Fusion

Oracle Virtual Box

  • Freeware Application
  • Available for Mac OS, Linux and Windows
  • Download: Accessible Here

Software for Students

  • Payware software available for free or a discounted price
  • Available from OnTheHub
    • login using your Coventry University credentials

4061CEM Virtual Machine

  • A single development environment for all students
    • no mismatched environments per student
    • easier for module staff to potentially debug any issues
  • Pre-made VMs with the required tools for this module
  • Provides a complete operating system with all tools for the module

Virtual Machine Tools and Software

  • Operating System: Kali Linux
    • username: student
    • password: password
  • Pre-installed Tools:
    • Python 3.x
    • JetBrains IntelliJ IDEA Ultimate
    • Git

Virtual Machine Download

Linux and the Course/Module

  • Requirement of the course is to learn various commands for Linux
  • Linux is used across the course on most modules
  • You will need to be able to use these commands from memory
    • repeat usage and practice will re-affirm this

Linux Commands (1)

pwd

  • Finds the current working directory
$ pwd
  /mnt/c/Users/me/IdeaProjects/

ls

  • Lists the files and directories inside the working directory
$ ls
  4061CEM  4061CEM_BruteForce  4061CEM_PortScanner  4061CEM_Transcoder

cat

  • Displays the contents of a file
  • Requires a filename to be provided that you want to display
$ cat data.csv
  name,age,course
  Ian,33,Computer Science
  Terry,Unknown,Computer Science

Linux Commands (2)

uname

  • Displays the basic information about the operating system
$ uname
  Linux

man

  • Displays the manual page for a command
  • Requires a command to be provided that you want the manual page for
$ man uname
  UNAME(1)                                                                              User Commands                                                                              UNAME(1)     

  NAME
         uname - print system information
  
  SYNOPSIS
   Manual page uname(1) line 1 (press h for help or q to quit

Linux Commands (3)

cd

  • Traverses to another directory
  • Requires a directory name or path to be provided
/home/ian$ cd test
/home/ian/test$ 

cd ..

  • Traverses back a directory
/home/ian/test$ cd ..
/home/ian$ 

cp

  • Copies a file
  • Requires the filename and extension to be copied, and the new filename (or path) it is being copied to
$ cp data.csv data1.csv
$ cp data.csv /home/ian/data_storage/data1.csv

Linux Commands (4)

mv

  • Moves a file from location \(a\) to location \(b\)
  • Requires the filename and extension to be moved, and the path it is being moving to
    • can also be used to re-name files
$ mv data.csv /home/ian/data_storage
$ mv data.csv data1.csv

mkdir

  • Creates a new directory on the system
  • Requires the name of the directory you want to create
    • can also be used to create a subdirectory inside another directory
$ mkdir test
$ mkdir test/subtest

rmdir

  • Removes a directory from the system
  • Requires the name of the directory you want to remove
$ rmdir test/subtest
$ rmdir test

Linux Commands (5)

rm

  • Removes a file from the system
  • Requires a filename that you want to remove
$ rm data.csv

rm -rf

  • Removes a file or directories from the system
    • does it recursively and forcibly
  • Requires a filename or directory that you want to remove
$ rm -rf data.csv
$ rm -rf test/

touch

  • Creates an empty file on the system
  • Requires a filename and extension to be provided
$ touch new_data.csv

Linux Commands (6)

echo

  • Often used to send data to a file
$ echo "Hello World" > new_data.csv 
$ cat new_data.csv
  Hello World
  • Can also be used to echo text to the terminal window
$ echo "Hello World" 
  Hello World

sudo

  • Runs a script with root privileges (administrator)
  • Requires the command that you want to run as root
    • will also require the password for current user
    • that is if it has administrative privileges
$ sudo apt install git

Linux Commands (7)

wget

  • Downloads a file or webpage from the internet
  • Requires a URL to the file or webpage you want to download
$ wget https://www.google.com

ps ux

  • Runs a list of all running processes on the machine
$ ps ux 
  USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
  ian         14  0.0  0.0   9320  5500 pts/0    Ss+  08:34   0:00 -bash
  ian       2811  0.0  0.0   9224  5400 pts/1    Ss   09:45   0:00 -bash
  ian       3449  0.0  0.0  10456  3240 pts/1    R+   10:02   0:00 ps ux

Linux Commands (8)

kill

  • Used to kill a running process
  • Requires the PID of the process you want to kill
    • can be obtained from the previous command ps ux
$ ps ux 
  USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
  ian         14  0.0  0.0   9320  5500 pts/0    Ss+  08:34   0:00 -bash
  ian       2811  0.0  0.0   9224  5400 pts/1    Ss   09:45   0:00 -bash
  ian       3531  0.0  0.0   6996  2464 pts/1    S+    10:04   0:00 nano test.txt
  ian       3533  1.5  0.0  21244  9792 pts/1    S+    10:04   0:00 vi test.txt
  ian       3534  0.0  0.0  10456  3280 pts/1    R+   10:04   0:00 ps ux
$ kill 3531
$ kill 3533
$ ps ux 
  USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
  ian         14  0.0  0.0   9320  5500 pts/0    Ss+  08:34   0:00 -bash
  ian       2811  0.0  0.0   9224  5400 pts/1    Ss   09:45   0:00 -bash
  ian       3534  0.0  0.0  10456  3280 pts/1    R+   10:04   0:00 ps ux

Goodbye

  • Questions?
    • Post them in the Community Page on Aula
  • Contact Details: