Introduction
1.1
History and Definitions
1.1.1 Definition of an
operating system:
By definition, an
operating system is a software used for managing the computer resources.
It allocates resources, schedules tasks, manages CPU time, memory, files,
directories disks, tapes, printers, terminals, etc.
The operating system also
provides an interface between you (the user) and the computer. This
interface may be graphical (GUI) or in the form of a text only terminal
where commands are typed and executed.
1.1.2 Types of operating
systems:
An operating system
can either execute only one task at a time or can be multi-tasking where
a computer can execute several tasks belonging to different users on the
system at the “same time”. Most of today's widely available O.S.
are multi-tasking, including UNIX, Linux, Windows 95/98/2000/NT, etc.,
but in the early days of computing this was not the case.
1.1.3 Multi-tasking and
time sharing
Multi-tasking means
that the computer is able to run several tasks at the “same time”. How
is this possible when most computers have only one CPU which is able to
execute only one instruction at one time? The answer is: by using time-sharing.
Time sharing means that all
the tasks are allowed to run for only a short amount of time (called
the time-slice) before they are preempted by the operating system. The
O.S. then runs the next task for another short amount of time,
and so on, until it comes back to the first task and the whole process
starts all over again.
The time slices and the delays
are very short (only about 10-20 milliseconds) so that even if the O.S.
does not run one task all the time, but comes back to it when it has
run all the other tasks, the user of the tasks has an impression that
all the tasks are running at the same time. So, you can practically
run your web browser, edit a file, send a document to the printer, perform
calculations, write to files at the same time, and all these appear
to be happening simultaneously.
1.1.4 History and versions
of UNIX
UNIX was developed
at AT&T Bell labs in 1969, and became widely available in 1975. It
was one of the first operating systems that were using the time sharing
idea that allowed multiple users to use the same computer and run different
tasks at the same time.
There are several versions
of UNIX, incluing BSD, System V, etc. and also different versions of
the UNIX shell (i.e. interface between the computer and the user), such
as Bourne shell, C-shell, TC-shell, Korn-shell, BASH, etc.
1.1.5 Portability and
popularity
UNIX is an open-type
operating system and is mostly written in C language, which means that
you can modify it relatively easily and tailor it to your organization's
specific needs as opposed to Windows. It is easily portable to different
hardware platforms (unlike Windows which can only run on a PC).
It is also free, and there are thousands of applications and software
packages that are also available for free download. Although most
PCs run Windows, UNIX is still very much alive, and there are many computers
that run one type of UNIX or another, such as workstations, servers,
routers, and even PCs (LINUX) etc.
1.2
Connecting to UNIX, logins and passwords 1.2.1
Connecting to jupiter.ksi.edu
Jupiter.ksi.edu is
the name of the UNIX server at KSI. To connect to it, we use the telnet
protocol, and you need to follow the procedure below:
For Windows-based PCs:
If you are at home, use dial-up
procedure to connect to the internet via your internet service provider
(ISP). If you are in the computer lab at KSI or if you have a
cable modem at home, you are already connected to the network.
Now, you need to do one of the following:
Invoke ms-dos (command) prompt
and type:
telnet jupiter.ksi.edu
or
press the Windows “Start”
button and choose “Run”. Then type
telnet jupiter.ksi.edu
or
If you are already using
a UNIX terminal, simply type:
telnet jupiter.ksi.edu
Next, if everything goes
well, you will see a greeting screen with the message as follows:
SunOS 5.7
Login:
1.2.2 System administrator
Before you login,
here is a few words about the sysadmin. This is the person responsible
for maintaining the UNIX system in a proper working order, and has the
access and authority to do virtually anything on the system (so be in
good terms with your sysadmin). The sysadmin is responsible for taking
care of a host of routine. He/She creates and deletes accounts,
can reset passwords (if you forget them), and creates backup files, among
other things.
1.2.3 Login name
Login name is a unique
identifier for you as a user on the system. It is assigned to you by the
system administrator when your account is created. It can be changed only
by the sysadmin as well.
Your login name usually
(but not necessarily) consists of the first letter of your first name,
and several (5-7) letters of your last name. For example, login name
for John Brown would probably be: jbrown, and login name for Wei Li
would probably be: wli.
In case several people have
the same name, usually a number is added to the login name. Different
login names will created such as jbrown1, jbrown2, etc. to avoid conflict.
Sometimes, though, login
names can be quite different from user’s real names (for example, w17294
or abc222). This depends on the policies of the organization that owns
the system and its system administrator.
If you do not know your login
name, you will not be able to cannot login. You must contact the
system admin., or KSI office to find out about your login name.
IMPORTANT NOTE: Login names
are case sensitive (i.e. jbrown is not the same as JBROWN). A very common
problem that many people do is forgetting to turn off the "CAPS_LOCK"
key when logging in.
1.2.4 Passwords
Initially, when your
account is created, the password for this new account is picked
by the sysadmin (more often it is your social security number). Once you
login for the first time, you should change the password immediately.
In case you forget your password, contact the sysadmin to reset the password
for you. The passwords are encrypted so even the system administrator
cannot read it or tell you about your current password. However,
the sysadmin can reset it for you and tell you what the new (reset) password
is. Again, in this case, you should change it as soon as you login
next time. Sometimes the system forces all users to change the password
periodically (for example, every 3 months or every week).
1.2.5 Password rules
When you change your
password, there are certain rules that you must follow. In addition to
these simple rules, the sysadmin may impose other password rules (for
example, that you cannot use previous 4 passwords).
Some common rules for password:
- Use any combination of letters,
numbers and punctuation characters
- Must be at least 6 characters
long
- Must have at least 2 letters
and 1 numeric character
- Cannot be the same as login
name or login name spelled in reverse
- Additional restrictions
imposed by the sysadmin.
Good practices when choosing
a password:
-Choose a password that is
not easily guessed. You should not choose your birthday, your
dog’s name, your girlfriend’s telephone number, etc. for a password.
- Do not use words from a
dictionary (some password guessing programs can successfully guess it)
- Add punctuation characters
to your password (like , ! ? . etc.)
- Use both upper and lower
case letters
- Use tricks: substitute “g”
with “9”, “1” with “!”, “b” with “6” etc.
IMPORTANT NOTE: Login names
are case sensitive (i.e. jbrown is not the same as JBROWN). A very common
problem that many people do is forgetting to turn off the "CAPS_LOCK"
key when logging in.
1.2.6 Logging in
Once you have your
account, know your login name and password, you are ready to login.
Now, you need to do the following:
Connect to jupiter.ksi.edu
using telnet utility, and on the prompt, enter your login name and password.
IMPORTANT NOTE: If your login
name and password contain numbers, do not use numerical keypad of your
keyboard to enter them (as this may not be interpreted correctly). Use
the regular number keys in the top row of your keyboard. In case you
have problems logging in, contact the KSI office to find out the proper
login name and password.
Once you login, you should
see a UNIX prompt (in the form of the dollar sign i.e. “$”)
which means that UNIX is waiting for you to enter a command.
1.2.7 Typing commands
All UNIX commands
are entered in lower case letters. UNIX is case sensitive. Therefore,
if you enter commands using capital/upper case letters, UNIX will not
understand those commands.
UNIX has a single-command
line editor, which means that it can read and interpret commands that
you enter on one line.
Once you type a command,
press ENTER key (or RETURN key) to execute it.
If you make a mistake when
typing commands, you can delete the previous character by pressing either
DEL key or BACKSPACE key on your keyboard. If neither “DEL” nor
“BACKSPACE” work (which is very unlikely), try “CTRL-H” (i.e. press
CTRL key, SHIFT key and H key at the same time).
You can delete the whole
line by pressing "CTRL-U" (i.e. press CTRL key, SHIFT key and U key
at the same time).
You can delete the previous
word by pressing "CTRL-W" (i.e. press CTRL key, SHIFT key and W key
at the same time)
1.2.8 Changing your password
CAUTION: read
this whole section before entering any commands
Once you login for the first
time, you should change the password that was assigned to you by the
sysadmin when your account was created.
To change the password, type:
passwd
and press ENTER key
i. UNIX will prompt you for
your current password (to prevent unauthorized persons from changing
your password while you are logged in and away from your desk).
ii. You should enter a new
password (that you will choose according to the rules and guidelines
discussed earlier). Make sure you remember this password in order to
be able to login again.
iii. Re-enter the new password
just to make sure you did not mistype it.
If everything goes well,
UNIX will report:
password changed for
[your username].
If you mistyped your current
or new password, or you did not follow the password rules, you will
receive an error message and you will have to repeat the process of
changing your password.
If you forget your password,
contact the sysadmin for resetting your password.
1.3
Using vi editor and some simple commands
1.3.1 About vi
vi is an editor, which
means that it allows you to create and modify plain text files. It is
not a word processing application (like Word for example), and you cannot
format text, change fonts, adjust margins etc., but you can type your
C/C++/assembly and any other programs in it.
At first glance, vi is not
what you might call a very user friendly editor and there are other
editors available for UNIX (such as emacs, X-emacs, pico, etc.), but
some of them may not be available on every system and some of them can
only be used with a Graphical User Interface (GUI) i.e. an X-windows
for UNIX.
The virtue of vi is that
it is present on every UNIX system, and that it can be used with any
terminal and any type of remote connection. Once you learn how to use
it, it becomes quite handy.
1.3.2 Modes of operation
in vi
vi has two modes of
operation. One for entering text (called INPUT mode which has 3
subclasses INSERT, OPEN and APPEND) and the other mode for entering commands,
searching through text, deleting and modifying, cutting and pasting text
etc.(called COMMAND mode).
When you first start vi,
you will be in the COMMAND mode, which means that you will not be able
to start typing text immediately.
IMPORTANT NOTE:
To switch from COMMAND mode
to INPUT mode:
Press I key (INSERT), or O
key (OPEN) or A key (APPEND).
I key (INSERT) is what you
normally press to go from COMMAND to INSERT mode and start typing text.
O key (OPEN)
is what you press to go from COMMAND to OPEN mode when you want to insert
a blank line and then continue typing text
A key (APPEND) is what you
press to go from COMMAND to APPEND mode when you want to add text to
the end of the line and then continue typing.
INSERT mode, OPEN mode and
APPEND mode are only different in this initial action (no action for
INSERT mode, create a blank line for OPEN mode, add text to the end
of the line for APPEND mode). After this, all three modes are exactly
the same.
To switch from INPUT mode
to COMMAND mode:
Press ESC key.
IMPORTANT NOTE: If you are
not sure which mode you are in (this may often happen), you can always
press ESC key, and that way you will for sure end up in COMMAND mode.
What happens when you press ESC key is that if you are in INPUT mode
you will end up in COMMAND mode. Again, if you are in the COMMAND
mode already, you will still be in COMMAND mode.
If anything seems to be out
of the ordinary, press ESC key and you will be in COMMAND mode, and
you can take it from there.
1.3.3 Starting vi
To start vi editor
and edit a file, type
vi file.txt
If the file.txt exists, vi
will open it, and you can edit it. If the file does not exist,
it will be created by vi when you save your work. If the file
is empty or not big enough for one screen, you will see “~” characters
that represent empty lines in the file. Remember that you are
in the COMMAND mode when you first start vi that does not allow you
to enter any text yet.
Note also that, while you
are using vi, your UNIX prompt ($)
disappears. It will reappear when you exit vi.
1.3.4 Typing text in vi
/ INPUT mode
First, you must switch
from COMMAND mode to INPUT mode. Press I key (INSERT) to go to INSERT
mode.
Now, you can start typing
some text (try for example to type in a paragraph from a book or from
this tutorial). Do not worry if you make mistakes, you can always
fix them later.
When you reach the end of
the line, press ENTER key.
While typing, you can correct
mistakes by pressing DEL key or BACKSPACE key. However, if you are in
the INPUT mode, you can only fix mistakes on the current line that you
are typing. Once you press ENTER key, vi creates a new line, and while
in INPUT mode, you cannot go and fix mistakes from any of the previous
lines.
So, in INPUT mode, you can
only type one line at a time (and press ENTER key) and correct mistakes
on the current line that you are typing. That is about all you can do
in INPUT mode.
1.3.5 Editing text/ fixing
mistakes in vi COMMAND mode Remember
that in INPUT mode you can only fix mistakes on the line that you are
typing.
Question: What happens if
you notice a mistake in some previous line?
Answer: You must go to COMMAND
mode and fix it.
Press ESC key and you will
go to COMMAND mode.
1.3.6 Moving around the file
in COMMAND mode
To be able to fix
anything, you must first position your cursor where the mistake is.
To do that, (be sure you are
in COMMAND mode now), use the arrow keys. Sometimes, these may not
work properly due to different keyboard configurations. If that is the
case, use H key, J key, K key, L key instead. See below:
"LEFT ARROW" key is the same
as h (i.e. move left by one character)
"RIGHT ARROW" is the same
as l (i.e. move right by one character)
"UP ARROW" key is the same
as k ( i.e. move up by one line)
"DOWN ARROW" key is the same
as j (i.e. move down by one line).
"CTRL-B" or "CTRL-U" move
up one full or half a screen
"CTRL-F" or "CTRL-D"
move down one full or half a screen
(i.e. press CTRL key, SHIFT
key and B/U/F/D key at the same time)
1.3.7 Deleting in COMMAND
mode
Once you position
your cursor to where the mistake is, you can use the following to delete
the mistake:
Press:
X key to delete one character
under the cursor
DW keys to delete one word
under the cursor
DD keys to delete the whole
line under the cursor
1.3.8 Undo changes in
command mode
If you delete or do
something unwanted, while in COMMAND mode:
Press:
U key to undo changes
IMPORTANT NOTE: if you press
U key twice, this will undo the previous undo, and the deleted text
will come back again.
1.3.9 Searching for a string
within a file
Sometimes, you need
to locate a particular pattern or string within a file. To do that, type
(while in COMMAND mode):
/pattern
(where you substitute the
word pattern with the word that you want to find, for example
/while
or /the)
vi will position the cursor
to the first occurrence of the pattern. Press N key to move to
the second occurrence of the same word and so on. If the end of file
is reached, vi will wrap the search from the beginning of the file.
Searching backwards is very
similar, except you have to type:
?pattern
1.3.10 Retyping over
mistakes and inserting text
When you delete the
mistyped text, position the cursor to where you want to begin typing i.e.
adding the deleted or missing text. Remember you are still in COMMAND
mode, and you must switch to INPUT mode.
Again, if you want to add
text to the very end of the line, you must press A key to go to APPEND
mode. Otherwise, if you want to start typing at the beginning or in
the middle of same line, just press I key (INSERT) to insert text.
Once you are in the INPUT
mode, you can start typing corrections.
1.3.11 Entering commands
in COMMAND mode To
go back to COMMAND mode, press ESC key.
There are several important
commands that will be covered here (there are more vi commands: consult
your textbook to get all of them). Most commands are preceeded by a
colon (: ) but not all of them are.
While in COMMAND mode, type
(this will appear at the bottom line of vi editor) and then press ENTER
key to execute the command:
:w file.txt
to save your work into a file called file.txt (you can of course specify
a different file name as long as it is a valid file name)
:set number
to be able to look at line numbers in the file. Line numbers will become
displayed, but they are not a part of the file. This is very useful
when editing C/C++ programs, as the compiler usually reports an error
in a file with a line number.
:set nonumber
turn off line numbering
:set showmode
display mode of editing (insert, append , open)
:set noshowmode
turn off mode display
:f
remind yourself of the name of the file you are editing and get basic
information about the file (number of characters, lines etc.)
:q!
quit vi without saving your work (careful here, you can loose all changes)
ZZ
quit vi but save the file prior to exiting (this command does not have
a colon character in front of it). IMPORTANT NOTE: Uppercase Z letters
must be used.
1.3.12 vi summary
When using vi, you
will often have to switch between COMMAND and INPUT mode. Command mode
is used for moving around the file (i.e. positioning the cursor), for
deleting mistakes, and for issuing commands. INPUT mode is used
for typing.
Remember that ESC key always
takes you to COMMAND mode.
Remember that I key, O key,
A key will take you from COMMAND mode to one of three INPUT modes (i.e.
INSERT mode, OPEN mode, APPEND mode).
Save your typed file using
:w
command, and exit vi using either ZZ
command or :q!
command.
1.4
Simple UNIX Commands

1.4.1 Listing contents
of a directory
Type:
ls
at UNIX prompt to
see the list of files in the directory. Once you type a vi file and save
it, you should be able to see the file “file.txt” in the list .
1.4.2 Displaying contents
of a file
To see contents of
a file, type:
cat [filename]
at UNIX prompt, where
filename is the name of the file that you want to see. For example, type:
cat file.txt
to see contents of file.txt
that you just created using vi.
Sometimes, when the file
is long (i.e. longer than can fit in one screen), you might have problems
with using cat
utility, because the contents of the file will run across the screen
too fast for you to see. To see file contents screen-by-screen, use
the more
utility, i.e. type:
more file.txt
This way, UNIX will prompt
you if you want to see more of the file. Press any key for more contents,
or press Q key to quit viewing the file and exit.
IMPORTANT Note: if a file
is short, there will be no difference between cat
and more.
|