Sie sind auf Seite 1von 13

Basics for UNIX

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

Operating System Concept


An Operating System is a collection of programs that acts as an intermediary between hardware
and the users.

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

Users in UNIX Environment


 General User who is using an application on UNIX. He should have the knowledge of
basic UNIX commands.
 Shell Programmer. This user should have the skills to write the scripts by using the
required UNIX commands. Scripting is very useful in industrial level to run the batch
jobs.
 Administrator. This user should have the required skill to handle all the administrative
work on Unix, such as user management (add the new users, add them to a group
user), File system management (giving appropriate permission of a particular file to
different users to avoid misuse of the file), hardware management (Hardware instal-
lation), software management (installation of different servers like ftp, http, telnet, ssh
etc) etc.
 System Programmer. This user should have the skill regarding performance manage-
ment, Socket programming, Unix Internals like memory management, Process man-
agement, system calls, inter process communication, interrupts etc.

Different Scripting languages in within UNIX


 Shell
 Perl
 Awk
 Python
 Ruby

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

Different Type of Emulator in UNIX


 Putty
 Secure CRT
 Telnet connection
 Exceed

Different Type of Shells in UNIX


 Bourn Shell
 Ksh (korn shell)
 Csh
 Bash

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.

UNIX File System


Unix file system contains 4-Blocks. Boot Block, Super Block, Inode Block, and Data Block as
shown below:

Boot Block Super Block Inode Block Data Block

Boot Block contains the booting program called “Bootstrap loader”.


Super Block contains the detail of the file system, that is how large it is, how many files are
there, how much space is left over, etc.
Inode Block contains the information about each file in a table called inode table. The table
contains the detail like owner of the file, group information, type of the file, file access permission,
last access time, last modification time, etc.
Data block contains the original data.
In UNIX we are dealing with 3 types of files. General files, directory files, and device files.
So in UNIX these are treated as files.
Some important file related commands are below:
Cat > file_name -> to create a file.
Cat file_name -> to view the content of the file.
Cat >> file_name -> to append to the file.
Mkdir directory_name -> to create a directory
Cp file1 file2 -> to copy the file.
Rm file1 -> to remove the file.
Rmdir dir1 -> to remove a directory provided directory should be empty.
Rm –r die1 -> to delete the directory recursively
Ls -> to list the files in the current directory.
-l -> long listing.
-a -> to display all the files including hidden files too.

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

Grep : The grep command is used to find a pattern in a file.


Grep <option> <pattern> <file name>
Eg : grep sample file1.txt
This will display those lines in the file which contains the pattern sample.
Different options of grep are :
v – display the lines which does not contains the pattern
i – ignore the case in pattern.
l – display the file names which contains the pattern

I/O Redirection and Piping


The redirection can be done by greater than symbol “ > “. It means the output can be redirected
to a file or can be redirected to another command for execution.
e.g. cat existing_file > new_file
here the output content of the existing file is redirected to new file.
Piping “|”, is a concept in unix, by the use of which, we can add multiple commands to get a
required output. Here output of one command is input to other command.
e.g ls –l | wc –l
here the output of ls command is input to the wc command. Here the output will show the
number of files in the current directory.

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

UNIX Basic Commands


Command Meaning
ls list files and subdirectories under the current directory.
ls -a List all files and directories

List all files and directories in detailed.


ls –l (l for long listing)
Get lots of details about the contents of directory.

mkdir make a directory


cd directory change to named directory
cd change to home-directory
cd ~ change to home-directory
cd .. change to parent directory
pwd (print working
display the path of the current directory
directory)
cp sourcefile destinationfile copy sourcefile and call it to destinationfile
mv sourcefile destinationfile move or rename sourcefile to destinationfile
rm file remove a file
rmdir directory remove a directory
cat file display the contents of file
more file display a file a page at a time

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

head file display the first few lines of a file


tail file display the last few lines of a file
grep ‘keyword’ file search a file for keywords
wc file count number of lines/words/characters in file
ls -lag list access rights for all files
chmod [options] file change access rights for named file
command & run command in background
^C kill the job running in the foreground
^Z Suspend the job running in the foreground
bg background the suspended job
jobs list current jobs
fg %1 foreground job number 1
kill %1 kill job number 1
ps list current processes
kill 26152 kill process number 26152

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.

Das könnte Ihnen auch gefallen