Charles Sturt University AussieMOO


AussieMOO's UNIX Introduction


This UNIX introduction works best if you open a telnet connection to your account on golum.riv.csu.edu.au, but most of this guide is also applicable to other UNIX systems where you have an account. The best way to learn about all the facilities in UNIX, is to try them out as you READ through these background notes. There are practical exercises and assignment questions at the end.

Information technology students should complete Assignment Questions 1 to 3 inclusive.

UNIX comes in many similar versions with very little differences. golum is a 64-bit DEC alpha machine running a version of UNIX called Digital UNIX V3.2C Worksystem Software (Rev. 148).

UNIX versions such as LINUX are also available for personal computers.

The MIS 3000 Survey results reveal the 1995 MIS trends in Australia. Our MOO server has been on various UNIX machines since September 1994. AussieMOO started out with Digital's ULTRIX, then moved to HP-UX before resting awhile with SUN's Solaris on the farrer SUN Sparc 4 machine. The tables below show the percentage of host operating systems, with UNIX as a clear industry leader, as well as the breakdown of variant UNIX platforms.

Table 1 Host Operating Systems 1995

			  %
UNIX			51.4
IBM OS/400		22.9
DEC VMS			16.7
PICK			6.3
HP MPE			5.6
Wang VS			5.5
IBM MVS			4.5
Others			xx

Table 2 UNIX variant platforms

		  %
SunOS		13.5
HP/UX		11.4
AIX		10.5
SVR4		8.1
Solaris		5.3
SCO Unix	3.9
Ultrix		3.5
DG/UX		3.4
OSF/1		2.4
Dynix		1.4
OSX		1.4
Others		7.8

The vast number of machines on the Internet running UNIX, makes it worthwhile to know how to manage files and to communicate with a remote UNIX machine. This document is meant to be a quick start guide for multiuser-computing professionals who have found a need to learn UNIX and the X-window interface. The lists of commands and exercises are arranged into functional groups rather than as an alphabetical listing.

UNIX History

Originally developed by AT&T Laboratories in the USA as an interactve, time-sharing operating system, the first version became available in the mid-seventies and has been steadily transported across many systems for commercial adaptation. Typical operatin g systems were developed by manufacturers using assembly language which meant it was tied to that hardware environment. The success of UNIX was attributed to its portability across various hardware platforms due to the fact that about 95% of UNIX is written in the high level programming language called C.

Directory tree structure (for a user called bsimpson)

A typical directory structure on golum for a user is shown below as a tree with the root or / directory as the parent directory.

		Tree			Key:

		/	(root)	 / 	root directory
	    /	   \			usr contains many sub-directories
	usr				bin most frequent system commands
     /    \				users contains user areas
   bin     users			acstaff academic staff user area
		\			bsimpson bsimpson user area
		acstaff
		  \
		  bsimpson

Finding your way around the UNIX directories is very similar to the pathway in most hierarchical trees found in other common operating systems such as DOS. The next section contains the list of commands concerned with UNIX files and directories.

UNIX Commands List 1: Files and Directories

This list contains some common commands needed after login to the UNIX account and are particularly good for the first-time user.

passwd 				change login password
date				print date
cal 1994			print calendar
help				ask for help
who				who is on the system
write				write to another user
man				print manual entries
ctrl - D			logout
logout 				terminate the session
learn 				computer instruction
ls				list contents of directory
ls -l				long format of the list
ls -ld				long format of a requested directory
ls -a				list all entries in the current directory
ls -al				list all entries in long format
pwd				print working directory
cd ..				change to parent directory
cd / 				change to the root directory
cd usr/users/acstaff/bsimpson	change to users home directory
cd home 			}
cd bsimpson			} change to the home directory
cat				concatenate files (type on screen)
more				file perusal filter (scrolling)

vi Text Editor

vi is a full screen text editor for UNIX.A text editor is a program for inserting or amending text in a file. A text editor is not a word processor although some text editors do include word processing facilities. The vi editor (pronounced "vee eye ") is available on all UNIX systems: other editors are not. Being able to use vi ensures that you will always have an editor available to you. Underlying the use of vi are two very important concepts.

Operating Modes There are two modes in which you use vi.

1 Command mode

This is the mode you are in whenever you begin to use vi. In this mode commands are used to move around and edit text objects such as words, sentences and paragraphs. Pressing the ESC key returns you to command mode.

2 Insert mode

This is the mode you use to type (insert) text into a buffer. There are several commands that you can use to enter this mode.

Text Buffer While using vi to edit an existing file, you are actually working on a copy of the file that is held in a temporary buffer. If you invoked vi with a new filename, (or no file name) the contents of the file only exist in this buffer.

Saving a file writes the contents of this buffer to the permanent file, replacing its contents. You can write the buffer to a new file or to some other file.

You can also decide not to write the contents of the buffer, and leave your original file unchanged.

Starting vi

   vi filename
The filename can be the name of an existing file or the name of the file that you want to create.

Quitting vi

To quit the vi editor: :q If you have edited (changed) the file you will be prompted with the message:

   No write since last change

You can either save the changes or quit without saving any of the changes you have made. To quit vi and save the contents of the buffer to the file that vi is being used to edit: ZZ or :wq

To quit vi without saving the contents of the buffer to the file::q!

To quit vi and save the contents of the buffer to a new file:

:w filename :q

An excellent vi tutorial exists at: UMICH

vi commands

Window Motions
	d		Scroll down (half a screen)
	u		Scroll up (half a screen)
	f		Page forward
	b		Page backward
	/string		Search forward
	?string		Search backward
	n		Repeat search
	N		Repeat search reverse
	G		Go to last line
	nG		Go to line n
	:n		Go to line n
	1		Redraw screen
	g		File information

Cursor Motions
	H		Upper left corner (home)
	M		Middle line
	L		Lower left corner
	h		Back a character
	j		Down a line
	k		Up a line	
	^		Beginning of line
	$		End of line
	l		Forward a character
	w		Forward one word
	b		Back one word
	fc		Find c
	;		Repeat find (find next c)

Input Commands (end with ESC)
	a		Append after cursor
	i		Insert before cursor
	o		Open line below
	O		Open line above
	:r file		Insert file after current line

Changes during insert mode

	h		Back one character
	w		Back one word
	u		Back to beginning of insert

Move text from file old to file new
	vi old
	"a10yy		Yank 10 lines to buffer a
	:w		Write work buffer
	:e new		Edit new file
	"ap		Put text from a after cursor

Deletion Commands
	dd		Delete line
	ddn		Delete n lines to general buffer
	dw		Delete word to general buffer
	dnw		Delete n words
	d)		Delete to end of sentence
	db		Delete previous word
	D		Delete to end of line
	x		Delete character

Recovering deletions
	p		Put general buffer after cursor
	P		Put general buffer before cursor

Change commands
	s		Substitute (ESC) - 1 char with string
	cw		Change word (ESC)
	cc		Change line (ESC) - blanks line
	c$		Change to end of line
	rc		Replace character with c
	R		Replace (ESC) with - typeover
	.		Repeat last change

Undo commands
	u		Undo last change
	U		Undo all changes on line

Rearrangement commands
	yy or Y		Yank (copy) line to general buffer
	"z6yy		Yank 6 lines to buffer z
	yw		Yank word to general buffer
	"a9dd		Delete 9 lines to buffer a
	"A9dd		Delete 9 lines; append to buffer a
	"ap		Put text from buffer a after cursor
	p		Put general buffer after cursor
	P		Put general buffer before cursor
	J		Join lines

File management commands
	:w name		Write edit buffer to file name
	:wq		Write to file and quit
	:q!		Quit without saving changes
	zz		Same as :wq
	:sh		Execute shell commands (d)

Parameters
	:set list		Show invisible characters
	:set nolist		Don't show invisible characters
	:set number		Show line numbers
	:set nonumber		Do not show line numbers	

Protecting Files: Owners, Groups and others

Protecting files is an important task on any network. UNIX has three privilege levels and file operations which are fundamental for all UNIX users:

Privilege levels:

		user	group	others

File operations:

		r (read)	w (write)	x (execute)

This information is available for each file and is coded in the following style:

	-rwxrwxrwx for a file
	drwxrwxrwx for a directory file

Key:
	-rw-r--r--
	^ ^  ^  ^
	a b c  d	   where  a  = the file type
			      b,c,d = rwx for user, group and others, in order.

	-rwxrwxrwx	is read, write and execute for everyone

	dr-xr-xr-x	is a directory to read and search only, for everyone.

Now apply these components of a typical directory listing in long format:

Long format directory listing

The long format of a directory file listing contains a lot of useful information such as the privileges attached to the file. The following example of such output has been labelled to indicate what it all means.

-rw-r--r--	1	bsimpson acstaff	417	May 24 17:24	README
		^	^	  ^		^	^	^	^
		a	b	  c		d	e	f	g

The following key reveals the meaning of the other components from the above example in the long format directory listing in UNIX:

	a = link count		    	d = byte size	

	b = owner name		  e,	f = date and time of last modification	

	c = group name			g = filename

The mode for the listing above indicates that the file has read only access for everyone and write access to the user or owner!

UNIX Commands List 2:

Creating, Managing, Deleting and Protecting files

This list of commands are useful when editing, managing and protecting the files in your UNIX account.

cp  			copy files
chmod			change mode (rwx file privileges)
umask			set file creation mask
rm			remove files
rm -r			recursively remove all files in a directory
mv			move or rename files
mkdir			make a directory
du			summarise disk usage
pr			print file
* 			regular expression wildcard
head -2 		print the first 2 lines of a file
tail -4 		print the last 4 lines of a file
find			find files
whereis			locate program
file			determine the file type
ln			make a link to another file
split			split a file into pieces
df			print free disk space
quota			display quota limits
tar			tape file archiver
pack			pack files
unpack			unpack files
cmp  			compare two files
diff  			find file differences
uniq			report repeated files
sort			sort and/or merge files
join  			database relational operator
fgrep  			search file for a string
egrep  			search file for an expression
wc			word count
dd			convert and copy a file
crypt			encrypt or decrypt a file
jobs			print list of jobs
fg 			resume job in foreground
bg 			resume job in background
stop 			suspend a background job
shl			shell layer manager
ps			report process status
sleep 			suspend execution
kill			terminate a process
at 

UNIX Commands List 3:

Special Shell variables, Editors, Communications

Shell variables:
set			set values of variables
path			defines the sequence of searched directories
setenv			set the environment variables
printenv		print the environment variables
unsetenv		remove the environment variables

Editors:
ed			text editor
vi			screen-oriented editor
ex			text editor available within vi

Communications:
uucp			UNIX to UNIX copy
uuname			list names of systems
uulog			print logging information
mail			send and receive mail
news			print news items
readnews		read news items
checknews		check if there are any news items
postnews		submit news items

I/O Redirection, Filters and Pipes

The > character can be used to redirect output of a process to a file instead of to the terminal screen:

		cat resume.txt > cv.txt

This command will cause the output of the file called resume.txt to be copied to a file called cv.txt instead of to the terminal screen.

UNIX uses a variety of mechanisms for interprocessor communication and the PIPE is often described as the most significant. The Pipe is a circular buffer which allows two processes to communicate as part of a producer/consumer model. It is a first- in, first-out (FIFO) queue which is written by one process and read by the other. Piping creates a a fixed size (bytes) buffer in memory and only one process can access the pipe at one time. The | character, used in piping, is detected by the sh ell or command language interpreter and causes the command on the left of the | to be the input of the command on the right of the | character. One common use is with the file perusal filter command: more

		ls -l | more

This command is useful when looking at large directory or file. By piping the output of the ls command into more, the output will stop at the first page, allowing you to scroll through at your control.

		cat parta partb 2>&1 | lp

This command spools the output of two files called parta and partb to a line printer, and combines the notions of redirection and piping.

Practical Exercises

This section reveals the output of some commands on golum and some insight into accessing and managing files. This series of practicals is a good way to examine the local file structure and organisation, before doing the Assignment Questions.

Exercise 1: UNIX Introduction

Check the output of some commands by experimenting with the UNIX commands for 15 minutes, using the various commands described in the notes. Here are some example commands and expected output:

golum> date							
Thu Jul 21 20:43:42 EST 1997
						
golum> cal
      July 1995     
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

golum> cal 8 1994

golum> cal 10 1996

golum> who
bsimpson    tty05        Jul 21 20:18                          
u9230045    ttyp0        Jul 21 20:09          (spc.riv.csu.edu.au)

golum> pwd
/usr

golum> ls -l
total 15194
-rw-r--r--   1 bsimpson acstaff       417 May 24 17:24 README
drwxr-xr-x   4 bsimpson acstaff       512 Jul 20 15:15 stut
-rw-r--r--   1 bsimpson acstaff  14475264 May 24 17:24 stut_nn.tar

golum> cat README 
contents of the files

Goodluck and let me know if you have any problems.

AussieMOO

Exercise 2: Getting to Know UNIX

  1. What is the output of the following sequence of commands?

    	golum> ls -l
    	golum> cd home
    	golum> ls -a
    	golum> cd /
    	golum> pwd
    	golum> ls -l | more
    	golum> ls -a
    	golum> ls -ld
    	golum> df
    
    
  2. Make a checklist copy of useful UNIX commands and make up you own sample test of each command.

  3. As you investigate their use on golum, practice with these commands and mark off each one as you proceed. As stated at the beginning, the best way to learn about the facilities of UNIX is to try them. The table below should be used as a guide. The mor e command is shown as an example.

    Checklist of commands		Actual Test used
    
    more				cat assign1.txt | more
    
    ...........................	..........................
    
    ...........................	..........................
    
    ...........................	...........................
    
    ...........................	...........................
    
    ...........................	...........................
    

    Assignment Questions

    Assignment Question 1 vi, pico and pine (8 marks)

    1. Use the vi or pico text editor to create a short text file (4 lines max.) called bio.txt which describes your background and reason for doing this subject and course.
    2. Use the e-mail facility called
      pine
      to send an e-mail message to your lecturer, a courtesy-copy (cc) to yourself at golum.riv.csu.edu.au, with bio.txt as an attachment.
    3. Read the mail message from step 2 above, and extract bio.txt as a file into your current directory
    4. Rename the file as bio2.txt and move it to another directory called "letters".

    Assignment Question 2: Operating System Study (12 marks)

    1. The UNIX operating system has several file protection features and providescommands to control access to files on a shared computer system. Investigate and compare the 'general' protection level associated with the files in the golum user area /home/a cstaff/wwwww that you can access, with those in your own user area. Report your findings.
    2. What is the significance of 'interrupts' and 'time slices' in a time-sharing, multiprogramming environment? Contrast how such an environment can be 'event-driven' against one that can be 'time-driven'.
    3. Describe how the resource allocation procedures of an operating system can prevent a 'deadlock' condition.
    4. Draw an 'onion-skin' model of an operating system. Explain the 'shell' environment and how it may used.

    Assignment Question 3: Your WWW Home Page in SIX steps: (4 marks)

    1. golum>mkdir public_html {creates a new directory called public_html}
    2. golum>cd public_html {change to the new directory)
    3. golum>pico index.html {creates a text file called index.html - your golum Home Page}

    4. At this stage, enter your own HTML or modify the sample code below. Substitute your golum username for
      jsmith99
      in the e-mail link below:

      <HTML>
      <HEAD>
      <TITLE>Quick Home Page</TITLE>
      </HEAD>
      <BODY>
      <H1> Heading level one of six</H1>
      <HR>
      <H3>Welcome to my first Home Page.</H3><P>
      The last word in this line is <B>bold</B>.<BR>
      <UL>
      <LI>First bulleted item in unordered list </LI>
      <LI>The following word is in <I>italics</I></LI>
      <LI>This is a link to the <A HREF="http://www.csu.edu.au">CSU Home Page</A>
      <LI>This is the last item in the list</LI>
      </UL>
      <HR>
      <ADDRESS><A HREF="mailto:jsmith99@postoffice.csu.edu.au">Your name goes here</A>
      </ADDRESS>
      </BODY>
      </HTML>
      

      Use CTRL-X to exit and save index.html

    5. golum>chmod 755 index.html {Changes file protection to rwx for owner, r-x for group and others}
    6. golum>lynx http://golum.riv.csu.edu.au/~jsmith99 {Uses the 'lynx' text browser to view home page}

    FORWARD to the X-window Practical

    References

    1. UNIXhelp for Users. [Online]. Available WWW at http://www.cit.gu.edu.au/services/UNIXhelp/
    2. Berlage, T. (1991). OSF/Motif: Concepts and Programming. Addison-Wesley, Wokingham, England.
    3. Christian, K. and Richter, S. (1994). The UNIX operating system. 3rd Ed. Wiley. New York.
    4. Johnson, E.F. and Reichard, K. (1991). Advanced X window Applications Programming. MIS Press. Portland.
    5. Kay, D.C. and Levine, J.R. (1992). Graphics File Formats. Windcrest/McGraw-Hill. USA.
    6. Poole, P.C. & Poole, N. (1991). Using UNIX by Example. Addison-Wesley. Sydney
    7. Stallings, W (1992). Operating Systems. Macmillan. New York.

    Note

    Digital Press and O'Reilly books also have many good references covering the X-window environment.

    Compiled by Ken Eustace, 1996


    Back to Main