First Indian Corporation - India
First Indian Corporation - India
1
Objectives
• At the end of this session, you will be able to
understand:
–What is UNIX and its history
–Various components of UNIX
–Why should we use UNIX
–How to log in and log out
–A few simple commands of UNIX
–vi Editor, its usage and some essential commands
2
What is UNIX?
• UNIX is a multi-user operating system that supports
multi-tasking.
• An operating system is a part of computer system
that acts like a manager to the system resources.
• In a multi-user o/s many users can access the same
machine simultaneously and the o/s will ensure that
all the users get the required support.
3
History of UNIX
• First developed at Bell Labs of AT&T
• Milestones in its lifetime :
1988 System VR4, 4.3BSD, POSIX
1971 On PDP11/20
6
Components of UNIX
• When you use UNIX, several layers of interaction are
occurring between the computer hardware and the user.
User
Windowing System
Shell
Applications Commands
Kernel
Hardware
The path of a file is found by traversing this tree from top till the file,
putting “/” in between the two files. For example:
The path of root directory is /
The path of bin is /bin
The path of mydir is /usr/mydir
10
Why should we use UNIX?
There are many reasons,
here are just a few:
Robust
Wide range
Effective
of Networked
use of
availability
resources
and uses
Multi- Security
Multi-user tasking
11
Things to Remember
Hey I keep typing in “CD
home” and it keep saying
command not found.
Stupid Computer!
12
Things to remember (contd…)
• There are two very special path symbols to keep in mind.
They are, “.” for current working directory and “..” for the
parent of the the current working directory.
• Also remember that filenames can be given in one of three
manners.
– Absolute, fully qualified and begins with a slash. Tells exactly
where the file is.
– Relative, no slash to lead off the filename. This means to look for
the file from where you currently are.
– No path, just type in a filename. In this case the file is assumed to
be in the current directory. If you type in the name of an
executable file it will traverse your path until it is found so it can
be executed. 13
Things to remember (contd…)
/ (Root)
15
Logging In (contd…)
• If you receive a message similar to “Login failed, please try
again,” you may have typed your userid or password
incorrectly. Try again, making sure to type in your userid
and password correctly. If you are still having problems,
contact your administrator.
• When you have successfully logged on, the system will
pause for a moment and display messages from the system
administrator, if any.
• The system will then display the command prompt. The
prompt signals that the system is ready for you to enter your
next command.
16
Logging Out and Changing Password
Type
Type “exit”
“exit” at
at the
the command
command prompt
prompt to
to log
log out
out of
of
UNIX.
UNIX.
18
A few rules to follow
• You should follow several rules with
UNIX commands:
– UNIX commands are case-sensitive, but most
are lowercase.
– UNIX commands can only be entered at the
shell prompt.
– UNIX command lines must end with a
RETURN.
– UNIX options often begin with a “-” (minus
sign).
– More than one option can be included with
many commands.
19
Change Directory (cd)
• cd
– This command is used to change the working directory
– Syntax: cd <directory name with path>
– Examples:
• To change to a directory called “mydir”, the command is:
cd mydir
• To change to a directory called “newdir” under the directory
“mydir”, the command is:
cd mydir/newdir
20
Present Working Directory (pwd)
• pwd
– When you log in the UNIX system places you in your
home directory.
– The pwd command will display the full pathname of the
current directory you are in.
– Syntax: pwd
– Output: /home/userid
21
Process Status (ps)
• ps
– ps stands for process status, is used to list the processes
running on a machine.
– The command without options shows minimal
information about the processes you are running.
– Syntax: ps [-options]
– Examples:
• To display the processes running by a particular user.
ps -fu <user name>
• To display the detail information about every processe
ps -ef
22
List (ls)
• ls
– This command is used to list the files and directories
under a directory.
– Syntax: ls [options] <path of the directory>
– Examples:
• To display the contents of current directory, type in the
following command:
ls
• To display the contents of directory “mydir” that is created
under the current directory, the command is:
ls mydir
NOTE: To get more information on the options of ls command, use
man command which is explained in the next slide. 23
Manual (man)
• man
– The standard on-line help facility available with UNIX is
electronic reference manuals, known as the man pages,
and you access them with the man command.
– Syntax: man <command-name>
– As mentioned in the previous slide to see help for ls, type
in:
man ls
NOTE: The output of man command is shown page by page. To be able
to go to next page, you need to press “Spacebar”.
24
vi Editor
• “vi” which stands for visual, is a display oriented
text editor.
• You can use vi to write programs, and anything else
you feel like.
• It is a powerful editor with far too many commands
to cover in detail in this session. Thus, we will be
discussing only a few important commands of this
editor.
NOTE: To learn the other commands, please take a look at the
appendix.
25
Starting vi
• To start vi, type in vi followed by the filename of
the file you want to open.
– Example: To open a file called “myfile” the command is:
vi myfile
• If the file does not exist, vi will create it for you.
• You can also start vi without giving any filename. In
this case, vi will ask for one when you quit or save
your work.
26
Modes of vi
• vi has two modes, command mode and input mode.
– In command mode, characters you type perform actions
like moving the cursor, cutting or copying text, or
searching for some particular text.
– In input mode, you type to insert or overwrite text. When
you start vi, it is in command mode.
• To switch from command to input mode, press the
“i” key (you do not need to press RETURN). vi lets
you insert text beginning at the current cursor
location. To switch back to command mode, press
ESC. 27
Modes of vi (contd…)
• You can also use ESC to cancel an unfinished
command in command mode.
TIP: Unfortunately, vi does not normally indicate which mode you are in. If you
are uncertain about the current mode, you can press ESC a few times. When vi
beeps, you have returned to command mode.
28
Cursor Movement
• You can move the cursor in command mode.
• vi has many different cursor movement commands.
The four basic keys appear below.
Keystroke Result
k move up one line
h or Backspace line move one character to the left
l or Spacebar line move one character to the right
j move down one line
29
Inserting Text
• You can insert text in a file only when the mode is set to
input mode.
• vi recognizes some a few special keystrokes as you type.
Keystroke Result
Backspace or Delete Erase the previous character
CTRL-W Erase the previous word
CTRL-U Erase the current line
RETURN Start a new line
30
Deleting Text
• To delete text, first move the cursor so that it covers
the first character of the group you want to delete,
then type the desired command from the table
below.
Command Function
x Delete only the current character
D Delete to the end of the line
db Delete from the current character to the beginning of the current word
de Delete from the current character to the end of the current word
dd Delete the current line
dw Delete from the current character to the beginning of the next word
31
Saving your work and exiting
• vi provides several means of saving your changes. Besides saving
your work before quitting, it’s also a good idea to save your work
periodically.
• To save type the following from the command mode:
– :w to save your work (“w” is for “write”).
• Similarly, to quit vi use the command:
– :q
• You can combine these two commands at once to write-and-quit by
entering command mode and typing:
– :wq
• In some cases you will want to abandon your changes since the last
time you saved your work (the last :w command). To do so, type:
– :q!which tells vi to quit without saving. Use caution when abandoning vi in this
manner because any changes you made will be permanently lost. 32
Windows-based tools to access UNIX
• The following two Windows-based tools can be used to
access UNIX:
– TELNET
• Click Start -> Run and type in “telnet <servername>”, the following
window will appear. Type in the userID and password on this screen.
• After the authentication is done, a command prompt will appear. You
may type in the commands at this prompt.
33
Windows-based tools to access UNIX
– Xceed
• This is another tool that can be used to access UNIX.
• We, at AMEX, generally use this tool to access UNIX. This
tool would be installed on your machines.
• When you launch this application, the following login screen
will appear.
34
Windows-based tools to access UNIX
• Type in your userID and password on this screen.
• After the authentication is done by the system, you would see
the following screen.
35
Summary
• Congratulations! You have successfully completed
this session.
• You have learned the following concepts in this
session: What is
What is
UNIX
UNIXandandits
its
history
history Various
viviEditor
Editorand
and Various
aafew components
fewsimple
simple components
commands of
ofUNIX
UNIX
commands
AAfew
fewsimple Why
simple Whyshould
should
commands
commandsof we
of we useUNIX
use UNIX
UNIX
UNIX
How
Howtotolog
loginin
and
andlog
logout
out
36