Beruflich Dokumente
Kultur Dokumente
Madhavi Surisetty
Basics for
UNIX
Madhavi Surisetty
Basics for UNIX
History
UNIX is a computer operating system originally developed in 1969 by a group of AT&T
employees at Bell labs including Ken Thompson, Dennis Ritchie and Douglas McIlroy. Today’s
Unix systems are split into various branches, developed over time by AT&T as well as various
commercial vendors and non-profit organizations.
Why UNIX
Open Source. It means the source code is free, any body can add the functionality
without disturbing the original functionality.
Unix is very famous because it is standardize. Standardize, means, extending the func-
tionalities by developing the new tools.
UNIX is interactive, Time-shared, Multi user, and multi tasking. Interactive means, it is
command oriented, everything need to be done only by issuing commands. Multi user
means, more than one user can work on a same kernel. Since more than one user
work on a kernel, the kernel performs the requests from different users, and queued
the tasks and with the use of time-sharing logic, it performs the task.
Unix is most secured OS. Because security can be maintained in file levels as well as
in user levels.
This is hardware independent OS.
Flavors of UNIX
System V at AT&T lab.
BSD (Berkeley Software Distribution)
Solaris at Sun Microsystems
AIX at IBM
HP-UX at HP
MAC OS X at Apple
3 TCS Confidential
Copyright 2007 by Tata Consultancy Services. No part of this publication may be reproduced, stored in a retrieval system, used in a spreadsheet, or transmitted
in any form or by any means – electronic, mechanical, photocopying, recording, or otherwise – without the permission of Tata Consultancy Services.
Basics for UNIX
UNIX Architecture
4 TCS Confidential
Copyright 2007 by Tata Consultancy Services. No part of this publication may be reproduced, stored in a retrieval system, used in a spreadsheet, or transmitted
in any form or by any means – electronic, mechanical, photocopying, recording, or otherwise – without the permission of Tata Consultancy Services.
Basics for UNIX
5 TCS Confidential
Copyright 2007 by Tata Consultancy Services. No part of this publication may be reproduced, stored in a retrieval system, used in a spreadsheet, or transmitted
in any form or by any means – electronic, mechanical, photocopying, recording, or otherwise – without the permission of Tata Consultancy Services.
Basics for UNIX
UNIX Servers
Different UNIX servers configured are:
Ftp server: Transferring the files from machine to machine.
Http server: Handles the HTTP request and response back.
Mail server: Looks after the mail exchange.
Telnet server: To connect to other machine.
Ssh (Secured shell) server: To connect to other machines through different secured
protocols.
Function of a Shell
Shell is an interface between user request and kernel services. Shell is an interpreter. It has
some ability to execute few of the user commands. Shell also contains some variables, user
can also create their own variables too.
All the commands can be broadly classified as Internal and External Commands. The
commands which are executed by shell are called internal commands. eg.- echo. On the other
hand the command those are not belongs to shell, that is whose executables are stored in the
/bin, /sbin, or in some other directory, are called external commands. eg – cat.
Different functions of a shell:
Provides the prompt ($) to the user, and wait for user input.
Parses the command line, executes the internal commands, and sends the request to
the kernel
After execution of the command it issues the prompt to the user again to get other
inputs for further processing.
6 TCS Confidential
Copyright 2007 by Tata Consultancy Services. No part of this publication may be reproduced, stored in a retrieval system, used in a spreadsheet, or transmitted
in any form or by any means – electronic, mechanical, photocopying, recording, or otherwise – without the permission of Tata Consultancy Services.
Basics for UNIX
User Environment
When any user login to a system, shell provides some predefined variables with some values,
which user can use. Important variables are PATH, TERM, PS1, PS2, etc.
You can see the details of environment variables by the use of “env” command.
You can change the environment variables by the use of “setenv” command. This changed
variables are valid as long as you are logged in.
7 TCS Confidential
Copyright 2007 by Tata Consultancy Services. No part of this publication may be reproduced, stored in a retrieval system, used in a spreadsheet, or transmitted
in any form or by any means – electronic, mechanical, photocopying, recording, or otherwise – without the permission of Tata Consultancy Services.
Basics for UNIX
Eg :
ls –l
shows the output in long listing format, the sample is shown below:
-rw-r--r-- 1 qaid qa 17 Jan 30 10:30 file1
drwxr-xr-x 5 qaid qa 4096 Jun 15 2007 file2-rw-r--r-- 1 qaid qa
74 Feb 12 2007 file3
The sample output has 7 columns.
1st column shows the permission to the file.
2nd column shows the number of links to the file.
3rd column shows owner of the file.
4th column shows the group owner.
5th column shows the size of the file. In UNIX size means number of characters in the file.
6th column shows date of last modified.
7th column shows the name of the file.
Find -> to find a file. The output shows the path of the searched file. The syntax is :
Find <find path> <selection criteria> <file name>
Eg : find / -name file1.txt
This command will search the file recursively from root (/) directory and show the path of the
file file1.
Basic Filtration
Filtration is needed to get the exact required data from the mixed output data. Some of the
filtration commands are below:
Cut : This display the selected column or field from any file or from the output of any command.
Eg :-
cut -d ‘ ‘ -f 2-7
retrieves the second to 7th column which should be separated by blank. Cut can work with
column delimited positional (each starts with certain offset) or separator-delimited column (with
column separator being blank, comma, colon, etc). By default, cut use a delimiter (defined in
-d option in example above) stored in a shell variable called IFS (Input Field Separators).
Sort : The “sort” command sorts information piped into it. There are several options that let you
sort information in a variety of ways. Eg :-
ps -ef | sort
sorts the output of ps command.
8 TCS Confidential
Copyright 2007 by Tata Consultancy Services. No part of this publication may be reproduced, stored in a retrieval system, used in a spreadsheet, or transmitted
in any form or by any means – electronic, mechanical, photocopying, recording, or otherwise – without the permission of Tata Consultancy Services.
Basics for UNIX
Unique : The uniq command can eliminate or count duplicate lines in a presorted file. It reads
in lines and compares the previous line to the current line. Eg :-
sort | uniq
Process in Unix
An instance of a running program is called a process. So whenever you are running a command
or any script, or in other word any request to the kernel, is called a process. You can find out
the process by the use of “ps” command. The general output of ps command is given below.
PID TTY TIME COMMAND
26760 pts/3 0:00 sh
28477 pts/3 0:00 ps
The above output shows 4 columns. PID stands for process ID. TTY stands for terminal,
TIME for the time when the process started, and COMMAND is the specific command. Ps
command with option f shows the output in more detail as shown below.
9 TCS Confidential
Copyright 2007 by Tata Consultancy Services. No part of this publication may be reproduced, stored in a retrieval system, used in a spreadsheet, or transmitted
in any form or by any means – electronic, mechanical, photocopying, recording, or otherwise – without the permission of Tata Consultancy Services.
Basics for UNIX
UID PID PPID C STIME TTY TIME COMMAND
qaid 26760 26318 1 04:36:50 pts/3 0:00 -sh
qaid 119 26760 2 04:37:43 pts/3 0:00 ps –f
ps command with option e shows all the system process as well as user process in the
machine.
To kill a process we can use kill command.
kill <PID>
In case any process is not getting killed then use -9 option for sure kill.
kill -9 <PID>
ftp commands
File transfer protocol (ftp), is used to transfer the file from one machine to other machine.
Once you will connect to any machine wirh ftp, you will get a ftp environment, where only ftp
commands work. The usable ftp commands are as below:
ftp <machine name> -> To connect to other machine for file transfer purpose.
get -> To transfer a single file from destination machine to the source machine.
mget -> To transfer multiple files from destination machine to the source machine.
put -> To transfer a single file from source machine to the destination machine.
mput -> To transfer a single file from source machine to the destination machine.
cd -> To change the directory
bye -> To end the ftp session.
Vi editor
The vi editor (short for visual editor) is a screen editor which is available on almost all Unix
systems. We can edit a file by using vi editor. This editor can be invoked by using the command
“vi”.
Eg:- vi <file name>
Vi editor has 3 modes such as command mode, insert mode, and execute mode. When you
are in command mode, letters of the keyboard will be interpreted as commands. When you
are in insert mode the same letters of the keyboard will type or edit text. To come out of any
mode you have to use ESC key.
Some vi commands are below:
When we open vi editor we are in command mode. To get into insert mode for editing of file,
we use i, a, o, and O keys.
Once we are placed into insert mode, then we can edit the file.
10 TCS Confidential
Copyright 2007 by Tata Consultancy Services. No part of this publication may be reproduced, stored in a retrieval system, used in a spreadsheet, or transmitted
in any form or by any means – electronic, mechanical, photocopying, recording, or otherwise – without the permission of Tata Consultancy Services.
Basics for UNIX
Then to save and quit the vi, we use ESC key to come out to execute mode and then type
colon (:) then ‘w’ for write and ‘q’ for quit.
Some use full key strokes in command mode in vi are :
x – to delete a character
dd – to delete a line
g – to go to last line of the file
(n)g – to go to nth line of the file.
UNIX Certification
Sun certified network administrator for Solaris 10 operating system
RHCE (Red Hat Certified Employee)
IBM AIX 5L Administrator
HP-UX System Administration
11 TCS Confidential
Copyright 2007 by Tata Consultancy Services. No part of this publication may be reproduced, stored in a retrieval system, used in a spreadsheet, or transmitted
in any form or by any means – electronic, mechanical, photocopying, recording, or otherwise – without the permission of Tata Consultancy Services.
Basics for UNIX
12 TCS Confidential
Copyright 2007 by Tata Consultancy Services. No part of this publication may be reproduced, stored in a retrieval system, used in a spreadsheet, or transmitted
in any form or by any means – electronic, mechanical, photocopying, recording, or otherwise – without the permission of Tata Consultancy Services.