Lecture 20 - UNIX 4
Home >
Lectures
> Lecture20
Objectives
- To introduce more about UNIX
Contents
- The vi Editor
- The pico Editor
- Editors
- Executing (or Running) a Program
- Unix Revision
- Discuss Assignment 3
The upcoming tutorial is in the
Unix Lab B1.11
1. The vi Editor
The vi (pronounced Vee I) editor is a character based, full screen, text editor. It uses its
own set of commands (you can get a summary from here
- it is printable postscript file which you must save to Unix and then print. In
mozilla, right click on the link and select Save Link As..., click Ok to
save the file, then print it).
Vi is a moded editor. This means that it operates in different
modes. When you first start it, it is in command mode. Here you
can give keystroke commands to move around the file, delete lines, copy,
paste, and the like. When you give one of the text insertion commands,
such as i, you move to insert mode where everything you
type goes into the file. You leave insert mode by pressing the ESCAPE
key, which returns you to command mode. There is also a bottom line
mode which allows more complex search and replace operations. The commands
are case sensitive e.g. a is different to A. Once you are familiar with the
commands, vi is extremely quick to use, particularly if if you are a touch
typist.
vi has a number of advantages:
- it is available on most UNIX systems
- it doesn't require a graphical environment - it can be used via a terminal
window e.g. via telnet
- it works well over slow communication lines
- once mastered it is extremely quick to use
Some useful vi commands:
To run
Modes
-
insert mode (insert text to left
of the cursor position)
-
command mode
Files
- Save As (Write) a file e.g. :w Test.java
- Save (Write) a file
- Open (Read) a File into the current document e.g. :r Test.java
Moving Around
- Left (Backwards)
- Right (Forwards)
- Up (Previous) one line
- Down (Next)
- Forward one word
- Back one word
- Beginning of line
- End of line
- Next Page
- Previous Page
- Move (Go) to line number n e.g. 100G goes to line 100
- Move (Go) to the start of the file
- Move (Go) to the end of the file
Editing Text
- Delete character cursor is on:
- Delete to end of word cursor is on:
- Delete current line
- Delete 'n' lines e.g. 2dd deletes 2 lines
- Copy (Yank) lines e.g. 3yy copies 3 lines
- Paste before current line
- Paste after current line
- Join current and next lines
- Undo last deletion or insertion
Exit
- Exit and save
- Quit without saving
Note: When you complete an editing session, you save the file and exit
using ZZ
2. The Pico Editor
pico is a basic full screen text editor that doesn't require a graphical
environment to run.
This can be useful if you are logging in from a system that doesn't have a
graphical environment. pico uses special keystrokes to perform commands, such as Ctrl+X to
exit, Ctrl+G for help. It doesn't use the mouse.
Some commands are shown at the bottom of the window. Many commands use the
control key (Ctrl).
To Run
Files
- Save (write Out) a file: Ctrl+O
- Type the file name (or use Ctrl+T to select an existing file)
- Open (Read) a File: Ctrl+R
Moving Around
- Left (Backwards): LeftArrow or Ctrl+B
- Right (Forwards): RightArrow or Ctrl+F
- Up (Previous) one line: UpArrow or Ctrl+P
- Down (Next): DownArrow or Ctrl+N
- Beginning of line: Ctrl+A
- End of line: Ctrl+E
- Next Page: Ctrl+V or F8
- Previous Page: Ctrl+Y or F7
Editing Text
- Delete character to the left: Backspace
- Cut text:
- Move the cursor to the start of the text to be selected
- Start selection: Ctrl+^
- Then move the cursor to the end of the text to select
- Cut selected text: Ctrl+K
- Paste (Uncut) text: Ctrl+U
- Find (Where is) text: Ctrl+W
- Insert a tab: Tab or Ctrl+I
Miscellaneous
- Refresh the window: Ctrl+L
- Display Cursor position: Ctrl+C
Exit
- Ctrl+X
- then Y to save, N not to save or Ctrl+C to cancel.
3. Editors
Unix is an old system, which has been updated constantly. There are many
available editors. Some include:
-
pico - a simple, easy to use, rather limited, full screen text editor
-
vi - the visual (full screen) extension to ex
-
nedit - a windows based (WIMP interface) editor for X windows
-
ed - a line mode editor (one line at a time)
-
ex - an extended version of ed
-
emacs - another full screen editor, which makes extensive use of control
keys. Very powerful.
-
sed - a stream editor which will apply a set of commands to multiple
files
-
awk - a pattern processing system.
4. 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!
-
Check the file permissions to see if a file is executable (ls -l)
5. Unix Revision
The following files exist on a fictional Unix computer:
/usr/home/student/absurnam/ass2.java
/usr/local/pub/bitpen/bj.java
/usr/local/pub/bitpen/unixcommands.html
/usr/local/pub/bitpen/ball.gif
/usr/local/pub/bitpen/ltub.gif
/usr/local/pub/win95stuff/ws_ftp.zip
/usr/local/pub/win95stuff/ws_ftp.txt
/sbin/ps
/sbin/ls
/etc/passwd
/etc/group
Draw a tree diagram showing all of the above files
Assuming your home directory is /usr/local/student/asur3,
give the commands to perform the following sequence, updating your tree
diagram as you go:
-
Ensure your home directory is your current directory
-
List the files in your home directory
-
List the files in your parent directory
-
List all of your files, including hidden files showing their permissions,
size, etc.
-
View the contents of the '/etc/passwd' file
-
How can you find out what Unix group you belong to?
-
What group do you think you belong to?
-
List the contents of the '/usr/local/pub/bitpen' directory, showing
permissions etc.
-
Display your present working directory name
-
Create a new directory called 'mytmp' attached to your home directory
-
Copy the passwd file into your new mytmp directory
-
Change into your new mytmp directory
-
Copy all files from /usr/local/pub/bitpen into your new mytmp
directory
-
Change the permissions of all the files in your mytmp directory
so that only you and users in your group can read and write them (This
will require two commands)
-
Delete your new mytmp directory (This will require
a number of commands)
6. Discuss Assignment 3
Further Reading
- UNIX Command
Summary
- 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).
Previous Lecture | Lecture Index |
Next Lecture |
Tutorial
Last modified
09-May-2005 by Tim Whitfort.
Copyright © 2003-2005
Brian Retallick &
Tim Whitfort