Lecture 17 - Introduction to UNIX
Home
Objectives
- To introduce the UNIX Operating System
Contents
- History
- The UNIX Network
- Some Features of UNIX
- The UNIX File System
- General UNIX Commands
- Simple File Maintenance Commands
- UNIX Command Summary
1. History
Unix started about 1970, when Ken Thompson and Dennis Ritchie (at AT&T, Bell
Labs) wanted a computer to use as a general productivity tool (word processing
etc) that many users could use at the same time. They had a Digital Equipment PDP7,
but were dissatisfied with the operating system. They were working on an OS called
Multics which would have multiuser capabilities, but it became large and unwieldy
so Bell Labs dropped the project. So they wrote the first version of Unix (The
original name of Unix was Unics which is a pun on Multics). In the process, they
also designed the C programming language.
Unix was made available to research and education and spread widely. It has been
substantially enhanced over the years. It is available for most current computers
(including versions for the PC and Macintosh). In 2001 Apple Computers introduced
the latest version of the Macintosh operating system, MacOS 10 also called Mac
OS X because the wonderful graphical interface of the Mac is built on top of
a full Unix OS (that controls memory management, disk access, interfacing with
peripheral devices etc.)
2. The UNIX Network
- The System Administrator is Howard Cock (h.cock@latrobe.edu.au)
located in DSSG. SITS can help with problems regarding
the UNIX networks.
- Mainly used in programming subjects
- The main UNIX lab that we will be using is room B1.11 (Linux PCs). The other
UNIX lab is 1.08 (Apple Macs)
Servers
There are two main servers, redgum for student use and ironbark for
staff.
redgum & ironbark
- Apple Xserve (these act as UNIX servers to any UNIX workstation, whether they
be PCs, Macs,...)
- Dual G5 processors
- 2GB RAM
- Total disk capacity is in terabytes (1000's of gigabytes)
- 6000 student accounts
- Disk space limited to 50MB per student account
- Backed up to hard disk nightly
- the main purpose of this is to restore the system if there is a major failure
- not to restore files accidentally deleted by students
Workstations
The UNIX workstations we will be using in this subject are located in lab B1.11
(Computer Lab 3, also known as itlab3) and are networked into redgum's disk drive
where your files are stored. The CS & CE Department has a number of different
types of UNIX workstations, running different flavours of UNIX.
- 24 Dell (IBM compatible) workstations (2GB RAM, 19in monitors, 256MB video
memory, DVD burners)
- Operating System: Linux
- Named indya, indyb, ...
- Room B1.11
- 24 Apple iMacs (2GB RAM, 20in monitors, 256MB video memory, DVD burners)
- Operating System: Mac OS X
- Room B1.08
Logging On & Passwords
Students automatically have accounts on the Macs (B1.08) and on redgum. To log
onto a Mac use your student on-line username (in lowercase) and password.
Registering for an account on the Linux Workstations
Before you can use the workstations in the Linux lab (B1.11) you need to register
for an account.
To register for an account in the Linux lab. apply online at http://hopper.bendigo.latrobe.edu.au/unix_account (You will need your student online username and password). You will receive an email and you need to click on the link in that email.
Note: if you change your student on-line password after you create your account
for the Linux lab, the password in the Linux lab will remain the same as it was.
3. Some Features of Unix
Unix has a fairly simple design philosophy. Understanding that philosophy helps to iron out
any problems that you may have.
It is Multi-User:
- Many users can use a Unix computer at the same time. They share it through
what is called time sharing. The operating system (Unix) protects each
user's data, programs, actions, etc from interfering with others.
It has individual user accounts:
- Users have usernames and passwords which identify them when they
log into the system. The username identifies the user and allows access to the
files owned by the user.
Unix is command driven:
- When you log into a Unix system, you are presented with a shell (a command
interpreter).
- This is a program which accepts commands from the user and then executes them.
- A number of different shells are available, but commonly used shells here are csh or tcsh.
- The user typically sees a prompt and types in a command. The shell reads
the command, and causes the appropriate action to occur. Typically, a command
is the name of a program which is to be executed, together with any arguments needed.
- The name of the shell program you are using is 'tcsh'.
Unix has a Hierarchical File System (see below)
4. The Unix File System
Unix has a Hierarchical File System:
- The Unix file system is made up of directories, plain files (normally
referred to simply as files) and special files.
- Directories are a kind of file that contains information about where
other files (including other directories) are.
- So, to find a file, one must read the directory which contains its location
information.
- Of course, since the directory is a file, we must first read the directory
which contains that location information etc.
There is a special root directory where it all starts:
- The is a special directory called "/" (slash) which is well known
by Unix.
- It, in turn, contains the location of other directories (an example is bin which
contains some basic command programs).
- Slash (/) contains the directory Users, which contains the directory
of fjsmith, which in turn contains the location of user fjsmith files.
- This directory is referred to as fjsmith's home directory and is
referenced as /Users/fjsmith
We refer to files by their absolute pathnames:
- A file can be referred to by its full or absolute pathname: this
is the list of directory names starting from the root directory (slash) needed
to find the file.
- So, if the user fjsmith wishes to refer to a file in her home directory
called afile.txt, she would type the full pathname: /Users/fjsmith/afile.txt
- This is a bit tedious, so we allow a simpler way.
Files can be referred to by relative pathnames:
- When you login, your working directory is set to your home directory.
- If a pathname is typed without a leading slash, it is taken from the
working directory, rather than from the root directory (slash).
- So, a filename on its own (without any slashes) refers to a file in the present
working directory (pwd). eg:
afile.txt
Not all files are stored on the local machine:
- The PC environment differentiates files from different physical locations with
a volume letter. eg. A: for a floppy, C: for the local hard disk, H: for your
home directory. Each of these volumes has its own directory tree.
- Unix supports only one directory tree. However, branches of the tree
can refer to files on another computer, or even to files on an attached floppy
disk.
- Files from one computer are mounted (by the system administrator) onto
the file system of another computer using NFS (the Network File System).
- Your home directory and your files are stored on redgum and all of the workstations
have these files from redgum mounted in the same structure as they appear on
redgum. This means that if you work on one machine and then move to another,
the files are the same.
- Every workstation has its own copy of the OS. Therefore, changes that are required
to the OS have to be replicated across all UNIX workstations of that type
Structure of LTUB's Unix files as you see them from a workstation:
| Directory |
Description |
| / |
Root directory |
| /dev |
device drivers for terminal, printers etc. |
| /etc |
local - commands (normally this holds the including the password file 'passwd'
) |
| /proc |
local - list/data of currently running processes |
| /sbin |
local - Unix command files |
| /tmp |
local - directory for temporary files |
| /Users |
NFS redgum - directory for all students' stuff |
| /Users/fjsmith |
NFS redgum - student fjsmith's home directory |
5. General Unix Commands
As noted above, Unix is basically a command driven operating system. This means
that users get the actions they want by giving commands. Commands all follow
the same basic form: the first word is the name of the command. This is followed
by options and arguments. Options are usually the minus sign "-"
followed by some letters which change the action of the command. Arguments are
usually the names of files on which the command is to act. Some useful commands
are set out below:
- exit
- closes the current session (logs out of the session) - you can also use Ctrl+D to
logout.
-
- ls [-al]
-
- lists the files in the current directory, similar to the old DOS 'DIR'
command. eg:
- ls -a all option lists all files, including
any whose name start with a dot (which are normally hidden).
- ls -l long option lists more information
about each file.
- ls -al all and long options (same as: ls - a
-l)
-
- pwd
- gives the full pathname for the working directory
-
- cd pathname
- changes the working directory to the new directory specified by the pathname argument
given. Note that "." (a dot on its own) refers to the current working
directory, and ".." (two dots) refers to the parent directory - the
directory which contains the location information for the current working directory.
-
- less filename
- copies the contents of the file to the terminal screen, one page at a time.
Note that if this produces odd results, or complaints about the computer not
knowing what kind of terminal you are using, you may need to set your environment
- see the tutorial.
-
- cat filename1 filename2 filename3 ....
- prints the contents of the files onto stdout (the screen), one file immediately
after the other.
-
- man commandName
- shows the online manual entry for the command.
-
- man -k keyWord
- lists the commands that may have to do with the keyWord given. eg:
- man -k copy lists
all commands that have anything to do with copying
man -k copy file lists all commands to do
with copying and/or files (whew!)
-
- ps [-ef]
- shows all current processes - including the ps process that generates the list.
- '-e' option shows all processes, '-f' provides a full listing
- so, 'ps -ef' lets you see what everyone is doing:-).
-
- who
- lists the users who are currently logged onto the system
-
- whoami
- identifies the current user (useful if you find an unattended machine)
-
- file pathname
- tells you what kind of file the argument is
-
- df
- shows the NFS mountings including the amount of disk free on your system
-
- du
- shows how much disk usage you have consumed.
6. Simple File Maintenance Commands
- To maintain an account a user needs to know how to create, delete, copy, move
and rename files.
- For good house-keeping the user also needs to know how to create subdirectories
and how to move files between them.
- Simplified versions of some file maintenance commands are shown below
Listing your files
- Command: ls
- Options are -a for all files and -l for a longer listing. eg:
ls -al
- The long listing provides extra information such as whether a file is a directory
of an ordinary file, permissions, owner, size and last date modified.
- ls actually has 28 different options! Read all about them by 'man ls'
- Use 'ls [-al] fileName1 fileName2 ...' to only view specified
files' information
Creating a file
- Usually performed by an application program, in the same way that your word
processor creates files in the PC environment
- Text editors are useful for creating text files:-).
- common text editors are called nedit, pico, ee (for easy-editor), and vi.
eg:
nedit myfile.txt creates the file myfile.txt
that you can edit within nedit
- Graphics files can be created with graphics programs, such a xv and gimp
Deleting files
- Description: Removes (deletes) a file or files
- Command Format: rm filename
- Example: rm myholidays.txt
Copying a file
- Description: copies a file or files. .
- Command Format: cp oldFileName newFileName
- Example: cp test1.java test2.java
- Note: Requires two arguments. specifying only one file name is an error
Moving or Renaming files
- Description: moves or renames a file or files..
- Command Format: mv oldFileName newFileName
- Examples: mv test1.java test2.java
- Warning: the oldFileName no longer exists.
- Note: Requires two arguments. specifying only one file name is an error
Viewing the contents of a file
- Description: views the contents of a file. The command to use depends on the
type of file e.g.: a graphical file requires a graphics program
- To view the contents of text files use less or cat:
- Command Format:
- less fileName
- cat filename
- Examples:
- less test1.java
- cat test1.java
Changing Directories
- Description: Change the current working directory. The directory can be a relative
or absolute pathname
- Command Format: cd dirName
- Examples:
- cd public_html
- cd /Users/tjwhitfort
- Note: all accounts have a public_html directory that is your home
web page directory
Executing (or Running) a Program
- Simply type the name of the program at the command line.
- Unix does not really differentiate between programs and commands. In fact,
commands are stored as programs!
Editing a text file
- text files contain only standard text characters (or keyboard characters)
- are edited by a text editor
- terminal-based text editors available include:
- nedit filename
- pico filename
- vi filename
vi is a very powerful, universal command-based text editor that
requires knowledge of the commands to work. As it is fast it is ideal for
text editing through a modem connection.
- Program source files are simply text files and can be edited by the above text
editors
- Other types of files are edited by a corresponding program. eg.:
- graphics files by graphics programs
- sound files by some multimedia program
6. Web Browsers
Firefox and Konqueror are two of the web browsers that are available on the workstations
in the Linux lab.
7. UNIX Command Summary
A UNIX Command Summary listing
commands relevant to Programming Environment is available.
Key Points
- redgum: a Server is mainly for student use
- ironbark: Server used for staff accounts and CS&CE Department web pages
- workstations: IBM Compatibles running Linux in the UNIX lab, and Apple Macs
- Unix
- is Multi-User
- has individual user accounts:
- is command driven
- has a Hierarchical File System
- Unix can be accessed from The PC Network
Further Reading
- UNIX Command Summary Guide
- Taylor, D. (2001) Sams Teach Yourself UNIX in 24 Hours. 3rd ed. Indianapolis,
Indiana: Sams. (ISBN: 0-672-32127-0; Cost: approximately $40-45; Format: Paperback;
Pages: 536; Comments: an excellent introduction to UNIX, with greater coverage
than Learning the UNIX Operating System).
- Das, S. (2006) Your Unix: The Ultimate Guide. 2nd ed. Boston MA: McGraw-Hill.
(ISBN: 0-07-252042-6; Format: Paperback; Pages: 706; Comments: more in depth
that Taylor).
Written by Tim Whitfort.