Tutorial 0A
Operating systems
Software
Operating System
Program 1 Program 2 Program n
User
Hardware
CPU Memory Disk
Operating systems
Microsoft Apple Unix
Windows 98 Windows XP Windows Vista Windows 8 Windows 10 Mac OS X Leopard BSD 4.3 Mac OS X Snow Leopard
Operating systems
Microsoft Apple Unix
Windows 98 Windows XP Windows Vista Windows 8 Windows 10 Mac OS X Leopard BSD 4.3 Mac OS X Snow Leopard
Operating systems
Microsoft Apple Unix
Windows 98 Windows XP Windows Vista Windows 8 Windows 10 Mac OS X Leopard BSD 4.3 Mac OS X Snow Leopard
Mac OS X Mountain Lion Mac OS X Mavericks Mac OS X Yosemite HP-UX Linux AT&T Unix Solaris Different from the others: the
GUI (graphical user interface) is independent of the OS
Files
In UNIX there are three basic types of files1. Ordinary Files: An ordinary file is a file on the system that contains data,
text, or program instructions. In this tutorial, we look at working with ordinary files.
2. Directories: Directories store special and ordinary files, and other
directories. For users familiar with Windows or Mac OS, UNIX directories are equivalent to folders. In particular, directories are organized in a
hierarchy, starting at the root directory.
3. Special Files: Some special files provide access to hardware such as
hard drives, CD-ROM drives, modems, and Ethernet adapters. Other
Shell commands
Command Description
ls List the files in the current directory
ls –l Give a long listing of the files in the current directory
ls –a List all the files in the current directory (including hidden
files = filenames that start with a “.”)
ls *.java Use “*” as a wildcard = list all files that end in “.java”
ls ~ List all files in the user’s home directory
pwd Display the current working directory
cd Progs Change current working directory to “Progs” (“go into”)
cd .. Change current working directory to parent directory
cd ~ Change current working directory to user’s home directory
Shell commands
Command Description
mkdir Tut0A Create a new directory
rmdir Tut0A Remove a directory (only if it is empty)
cd - Change back to the previous working directory
echo “abc” Display a string on the screen
cat Greet.java Display the contents of a file
cp A.java B.java Make a copy of a file
mv B.java C.java Change the name of a file
mv A.txt ~ Move one file to another directory
Shell commands
View the manual page for some command:man ls
More commands:
cat Display File Contents cd Changes Directory to dirname
chgrp Change file group chmod Changing Permissions cp Copy source file into destination file Determine file type
find Find files grep Search files for regular expressions head Display first few lines of a file ln Create softlink on oldname
ls Display information about file type mkdir Create a new directory more Display data in paginated form mv Move/rename a file
pwd Print current working directory rm Remove/delete filename
rmdir Delete an existing directory if empty tail Prints last few lines in a file
More commands!
awk Pattern processing language cmp Compare contents of two files
comm Compare sorted data cut Cut out selected fields of file diff Differential file comparator expand Expand tabs to spaces
join Join files on some common field perl Data manipulation language
sed Stream text editor sort Sort file data
split Split file into smaller files tr Translate characters
uniq Report repeated lines in a file wc Count words/lines/characters
vi Visual text editor vim vi improved
fmt Simple text formatter spell Spell checker
Redirection and pipes
The shell is very, very powerful. One important feature is “redirection”:
■ Read input from a file
$ sort < mydata.txt
■ Write output to a file
$ sort mydata.txt > sorted.txt
■ Append output to a file
$ sort moredata.txt >> sorted.txt
■ Combine the above
$ sort < somedata.txt >> sorted.txt
Another feature is “pipes”:
■ Write output to another program
Java compiler and execution
Greet.java Greet.class
javac Greet.java
Java compiler
java Greet
Java virtual machine
Java compilation & execution step-by-step
Make a new directory for your programs$ mkdir RW114 $ cd RW114
Use an editor (such as gedit) to write the following program
Save it in a file called “Greet.java” public class Greet {
public static void main(String[] args) { System.out.println("Hello, world!"); }
Java compilation & execution step-by-step
Compile the program$ javac Greet.java $ ls
Greet.java Greet.class
Check the java version (just for interest’s sake)
$ java –version
java version "1.7.0_45”
Java(TM) SE Runtime Environment (build 1.7.0_45-b18) Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08)
Execute our program
Java compilation & execution step-by-step
Change the work “public” to “pubic”$ javac Greet.java
Greet.java:1: error: class, interface, or enum expected pubic class Greet {
^
1 error
Switch on line numbers to find the errors
Correct the previous mistake. Now delete the last “}“ in the program.
$ javac Greet.java
Greet.java:4: error: reached end of file while parsing }
^
Java compilation & execution step-by-step
Correct the previous mistake. Replace “Hello, world!” with 2/0.
$ javac Greet.java $ java Greet
Exception in thread "main” java.lang.ArithmeticException: / by zero at Greet.main(Greet.java:3)
The first kind of error is a compile-time error. Java does not even produce .class file.
The second kind of error (above) is a run-time error. These are more difficult to fix.
Which computer must I buy?
■ It does not really matter!
■ If possible, wait and determine your needs.
– How are other students using their computers? – Does it work for them?
– Do they bring it to class, or mostly leave it at home?
■ The CPU and harddrive specs are not too important.
– 500 GB harddrive space is enough for most people.
■ The most important spec is memory!
– Buy as much as possible.
– At the very least 4GB, but aim for 8GB.
■ http://www.sun.ac.za/infoteg
– IT Service Catalogue (left menu under IT LINKS) – Purchasing
– Hardware
How do I install Ubuntu
■ In this course, we are using Ubuntu
– Ubuntu = Linux + other bundled software
■ You can buy an installation CD from Ed Burger (NARGA A) for R20 (?) ■ Installation should be easy, but if you have trouble, bring your PC to the