Professional Documents
Culture Documents
Wipro Confidential 3
Operating Systems
Wipro Confidential 4
Unix Operating System
Wipro Confidential 5
Unix flavors
Every Unix-box hardware vendor come out with their version of Unix.
These versions has all Unix System V features tuned to work
with their hardware architecture.
Wipro Confidential 6
Unix Architecture overview
Wipro Confidential 7
Unix Architecture overview
Wipro Confidential 8
Files and processes
Wipro Confidential 9
The Directory Structure
Wipro Confidential 10
The Directory Structure
/
Working Directory
File 1
Current directory where user is placed
File 3 File 10
File 4
Wipro Confidential 11
Accessing a UNIX System
Wipro Confidential 12
Logging In and Logging Out
Upon providing the right user id and password, Unix starts a user
session and a command interpreter is spawned.
Wipro Confidential 13
Space Management / mount points
A file system is created on a hard disk and same can be mounted on the
Unix system.
File System creation is the process of readying a portion of hard disk for Unix to
keep its files.
Mounting is a process by which the file system is made available to the users.
Once mounted, the file system is available under the directory structure as a
directory.
There are commands to describe the mounted files systems / mount points.
“df” is such a command available in Unix.
Wipro Confidential 14
Backup & Recovery
Backup
Backup is the process in which data stored in a computer is copied to
an alternative storage medium (e.g Tapes, CDs etc..)
Hot & Cold Backup
Backups taken during the normal system operations are called hot backups.
Here the files could be get modified while backing them up.
Cold backups are taken while system is not performing any file operations.
All cold backups will be stable and are independent backups.
Recovery
Process by which system’s data is restored from backup device after a
system/media crash.
Wipro Confidential 15
UNIX Shell
A Unix shell is the command interpreter, the primary user interface to UNIX which
interpret and execute commands
A Shell can be “tuned” for each user by keeping the initialization commands, scripts
in the shell startup file.
Shell scripting allows users to write procedural programs using shell scripting
language. These scripts can be executed within the shell.
Wipro Confidential 16
Main memory / Shared memory
Kinds of Memory:
Main - The physical Random Access Memory located on the CPU
motherboard that most people think of when they talk about RAM. Also
called Real Memory. This does not include processor caches, video
memory, or other peripheral memory.
File System - Disk memory accessible via pathnames. This does not
include raw devices, tape drives, swap space, or other storage not
addressable via normal pathnames. It does include all network file
systems.
Swap Space - Disk memory used to hold data that is not in Real or File
System memory. Swap space is most efficient when it is on a separate
disk or partition, but sometimes it is just a large file in the File System
Shared Memory
Part of Main memory which is shared between processes across unix
users. Typically each process get part of main memory as a private
area, where only that process operates. Shared memory is the place
where multiple processes has access to.
Wipro Confidential 17
Unix Processes
Background processes
Processes that are run non-interactively. Such processes are not
associated with any terminal. Kernel processes are examples of
background processes. A user can submit such processes from
command prompt by appending the command with “&” sign.
Input / Output
Each process has the following devices attached to it.
Standard input – Device to get the input data. Normally the keyboard.
Standard output – Device to output data from the process. Normally the
terminal.
Standard error – Device to output error messages. Normally the terminal.
Wipro Confidential 18
User Management
User
Unix users created to access the system. A password is always
attached to each user id. The right combination of user id and
password allows one to access the Unix system and create a Unix
session.
Groups
Unix administrator can create Groups where one or more Unix users
can made members.
Various level of privileges can be set to group, which will be applicable
to all group members.
One unix user can be made members of multiple groups.
Wipro Confidential 19
File / Directory Permissions
Wipro Confidential 20
Popular Unix Commands
NAME
man - find and display reference manual pages
SYNOPSIS
man [ - ] [ -adFlrt ] [ -M path ] [ -T macro-package ]
[-s section ] name ...
man [ -M path ] -k keyword ...
man [ -M path ] -f file ...
DESCRIPTION
The man command displays information from the reference
manuals. It displays complete manual pages that you select
by name, or one-line summaries selected either by keyword
(-k), or by the name of an associated file (-f). If no
manual page is located, man prints an error message.
Source Format
Reference Manual pages are marked up with either nroff(1) or
sgml(5) (Standard Generalized Markup Language) tags. The
man command recognizes the type of markup and processes the
Wipro Confidential 21
Popular Unix Commands - Navigation
$
$ pwd
/u14/home/gie
$
$ cd ../..
$ pwd
/u14
$ ls
GIE_DATA_CORR.fmb home patchsso visappl
TT_DB lost+found testdata viscomn
$ ls -l
total 992
-rw-r--r-- 1 gie users 483328 Jan 7 17:20 GIE_DATA_CORR.fmb
drwxr-xr-x 2 root root 512 Jan 23 20:10 TT_DB
drwxrwxrwx 10 root other 512 Dec 1 14:57 home
drwx------ 2 root root 8192 Apr 16 2002 lost+found
drwxr-xr-x 6 app1159 dba 512 Oct 15 13:43 patchsso
drwxr-xr-x 2 ora1159 dba 512 Oct 7 18:45 testdata
drwxr-xr-x 204 app1159 dba 3072 Jan 19 10:08 visappl
drwxr-xr-x 9 app1159 dba 512 Sep 3 23:29 viscomn
$
$ ls -CF
GIE_DATA_CORR.fmb home/ patchsso/ visappl/
TT_DB/ lost+found/ testdata/ viscomn/
$
Wipro Confidential 22
Popular Unix Commands – File Operations
$ touch TeamRainbow
$ ls -l TeamRainbow
-rw-r--r-- 1 gie users 0 Jan 26 14:45 TeamRainbow
$ mv TeamRainbow Batch100
$ ls -l Batch100
-rw-r--r-- 1 gie users 0 Jan 26 14:45 Batch100
$ chmod g+w Batch100
$ ls -l Batch100
-rw-rw-r-- 1 gie users 0 Jan 26 14:45 Batch100
$
$ su
Password:
# chgrp other Batch100
# ls -l Batch100
-rw-rw-r-- 1 gie other 0 Jan 26 14:45 Batch100
#
# chown root Batch100
# ls -l Batch100
-rw-rw-r-- 1 root other 0 Jan 26 14:45 Batch100
#
# rm Batch100
#
# ls -l Batch100
Batch100: No such file or directory
#
Wipro Confidential 23
Popular Unix Commands – File Operations
$ ls -l
total 0
-rw-r--r-- 1 rainbow rainbow 0 Jan 26 14:52 test
$ mkdir Mydir
$ ls -l
total 2
drwxr-xr-x 2 rainbow rainbow 512 Jan 26 15:03 Mydir
-rw-r--r-- 1 rainbow rainbow 0 Jan 26 14:52 test
$ cd Mydir
$ ls -l
total 0
$ cd ..
$ pwd
/u02/home/rainbow
$ rmdir Mydir
$ ls -l
total 0
-rw-r--r-- 1 rainbow rainbow 0 Jan 26 14:52 test
$
$ cat test
This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
$
Wipro Confidential 24
Popular Unix Commands
“clear” – Clear screen
“date” – Displays system date
“echo” – Prints the argument values to screen
“file” – Shows the type of file
“passwd” – Command to change the user password
“uid” – Shows the current user & group details
“ps” – Shows the current processes running
$ date
Mon Jan 26 15:14:18 IST 2004
$
$ echo This is a test
This is a test
$ echo $LOGNAME
rainbow
$ file *
test: English text
$ file /bin/at
/bin/at: ELF 32-bit MSB executable SPARC Version 1, dynamically linked, stripped
$ id
uid=1099(rainbow) gid=1005(rainbow)
$
$ passwd rainbow
Enter login password:
New password:
Re-enter new password:
passwd (SYSTEM): passwd successfully changed for rainbow
$ ps
PID TTY TIME CMD
11363 pts/7 0:00 ksh
10540 pts/7 0:00 sh
$ ps -fu gie
UID PID PPID C STIME TTY TIME CMD
gie 9235 9233 0 14:30:08 pts/7 0:00 -ksh
$ ps -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
8 S 1099 11363 10540 0 51 20 627e21f8 207 627e2268 pts/7 0:00 ksh
8 S 1099 10540 9235 0 51 20 6344b668 121 6344b6d8 pts/7 0:00 sh
$
Wipro Confidential 25
Popular Unix Commands
“cal” – Calendar program
“cut” – Shows file contents after vertical filtration
“grep” – Shows file contents after horizontal (lines) filtration
$ cal
January 2004
S M Tu W Th F S
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
$
$ cat test
This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
$
$ cut -c1-10 test
This is li
This is li
This is li
This is li
This is li
$
$ cut -d' ' -f3 test
line
line
line
line
Line
$
$ grep [35] test
This is line 3
This is line 5
$
Wipro Confidential 26
Popular Unix Commands
“head” – Shows the initial part of the files
“tail” – Shows the trailing part of the file
“sort” – Shows the file contents after sorting
$ cat test
This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
$
$ head -2 test
This is line 1
This is line 2
$
$ head -4 test
This is line 1
This is line 2
This is line 3
This is line 4
$
$ tail -3 test
This is line 3
This is line 4
This is line 5
$
$ cat test
This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
$
$ sort -r test
This is line 5
This is line 4
This is line 3
This is line 2
This is line 1
$
Wipro Confidential 27
Popular Unix Commands
$ cat test
This is line 1
This is line 2
This is line 3
This is line 4
This is line 5
$
$ cat test1
This is line 1
This is line 2
This is line 3
$
$ diff test test1
4,5d3
< This is line 4
< This is line 5
$
$ cd ..
$ pwd
/u02/home
$
$ find . -name 'test' -print
./rainbow/test
./abshah/test
find: cannot read dir ./easdba/bin: Permission denied
$
Wipro Confidential 28
Pipe - Feature
Unix provides a powerful feature in which output from a command can be directed as input for another
command. This way, commands can be joined to process data in a very efficient manner.
Here, output of the “cat” command (file contents) are fed to command “sort”. The final output of this
command will be sorted file contents
$ cat test
John received 30 marks
Peter received 25 marks
Abraham received 15 marks
$
$ cat test | cut -d' ' -f1,3 | sort
Abraham 15
John 30
Peter 25
$
$ cat test | cut -d' ' -f1,3 | sort +1
Abraham 15
Peter 25
John 30
$
Wipro Confidential 29
vi – Unix Text Editor
“vi” – is the most popular text editor available in Unix. It operates in two modes,
command & input mode.
In the command mode, vi accepts commands.
In the input mode, whatever user types are taken as file contents.
While in input mode, pressing “Esc” will change the mode into command mode.
Wipro Confidential 30
Shell Variables
Unix allows you to define variables within a Shell. Unlike other programming languages, Shell variables
do not have any types. All values are stored as character strings.
$ env
_=/usr/bin/env
HZ=100
PATH=/usr/bin::/usr/local/bin::/usr/opt/SUNWmd/sbin
LOGNAME=rainbow
SHELL=/bin/sh
HOME=/u02/home/rainbow
TERM=ansi
PWD=/u02/home/rainbow
TZ=IST
$
$ TESTVAR="Hello World"
$
$ echo $TESTVAR
Hello World
$
$ ksh
$
$ echo $TESTVAR
$ exit
$ export TESTVAR
$
$ ksh
$ echo $TESTVAR
Hello World
$ exit
$
Wipro Confidential 31
Introduction to Shell Scripting
Shell script is a script file which contains commands and other control
statements. A shell script can be executed within a Unix shell. Unix shell will
execute each line in the shell script like any other interpreter.
$ vi myshell.ksh
ls -l
date
echo "Log Name is : " $LOGNAME
~
~
~
~
~
~
~
~
~
"myshell.ksh" [New file] 4 lines, 43 characters
$ ls -l myshell*
-rw-r--r-- 1 rainbow rainbow 43 Jan 26 16:31 myshell.ksh
$ chmod +x myshell*
$ ls -l myshell.ksh
-rwxr-xr-x 1 rainbow rainbow 43 Jan 26 16:31 myshell.ksh
$ myshell.ksh
total 6
-rwxr-xr-x 1 rainbow rainbow 43 Jan 26 16:31 myshell.ksh
-rw-r--r-- 1 rainbow rainbow 74 Jan 26 15:51 test
-rw-r--r-- 1 rainbow rainbow 45 Jan 26 15:40 test1
Mon Jan 26 16:31:42 IST 2004
Log Name is : rainbow
$
Wipro Confidential 32
Introduction to Shell Scripting
Wipro Confidential 33
Class room Assignment
Wipro Confidential 34
Thank You
35