Unix - Day 1: Intermediate Level
Unix - Day 1: Intermediate Level
Unix - Day 1: Intermediate Level
Intermediate Level
Learning approach
The following are strongly suggested for a better learning and understanding of this course:
Noting down the key concepts in the class, explained by the educator Analyze all the examples / code snippets provided Study and understand the self study topics Completion and submission of all the assignments, on time Completion of the self review questions in the lab guide Study and understand all the artifacts including the reference materials / elearning / supplementary materials specified Completion of the project (if applicable for this course) on time inclusive of individual and group activities Taking part in the self assessment activities Participation in the doubt clearing sessions
Course Objectives
To introduce the Unix Operating System To develop an ability to use Unix commands To develop an ability to use Unix utilities To introduce the security features in Unix To introduce the important features of vi editor To develop an ability to write programs in shell
Course Pre-requisites
For better understanding of this module, you should be conversant with Operating System Concepts and Programming Basics
Unix in Industry
Organizations use different implementations of Unix for creating and deploying applications as Unix is a very popular Operating System Many implementations use databases which are set-up on Unix Servers Many web based projects are deployed on Unix Web Servers like Apache are commonly deployed on Unix platforms With the advent of Mono, Unix can also cater to DotNet applications Hence Unix is considered to be very important in the industry In Infosys, there are many projects which use Unix in its various flavors and require good understanding of Unix for its team
5
C-Map
Expectations
At the end of the Unix module, the candidate should be conversant with the following
Unix architecture Usage of various types of Unix commands Security features in Unix Unix utilities vi editor Shell programming
References
Sumitadha Das, Unix Concepts and Applications ,3 rd Edition,TMH Yashavant P. Kanetkar, Unix Shell Programming,BPB Brain W. Kernighan and Rob Pike, The UNIX Programming Environment Stephen Prata, Advanced UNIX - A Programmers Guide. Sumitadha Das,, Your Unix: the ultimate guide.,TMH Stephen G. Kochan and Patrick H. Wood, Exploring the Unix System James R. Groff, Paul N. Weinberg , Understanding Unix - A conceptual guide Maurice J. Bach, The Design of the Unix Operating System
8
References
Introduction to Unix Shell Programming
http://kshop/kshop/showdoc.asp?DocNo=8011
UNIX-Shell Programming
http://kshop/kshop/showdoc.asp?DocNo=162573
9
10
Introduction to Unix
What is Unix?
Unix is a multitasking, multi-user, time-sharing operating system
Evolution of Unix
In 1965 AT&T along with a group of other companies started working to create a time-sharing system, MULTICS In 1969 AT&T has dropped the idea of MULTICS project. Ken Thompson has written first version of UNICS on a PDP-7 machine. UNICS stands for Uniplexed Information and Computing Services. UNICS is changed to UNIX.
11
Introduction to Unix
Flavors of Unix
AIX (Advanced IBM Unix) HP-UX ( Hewlett Packard Unix) MINIX (Minimal Unix) XENIX SCO UNIX SOLARIS LINUX, etc
12
Features Of Unix
Portability
In 1973, Unix kernel is written in C, hence it can be installed on machines from microcomputers to mainframe computers
Security
Proper username and password are required to work on Unix Access permissions are given to prevent unauthorized access of files
13
Features Of Unix
Redirection Tools
Used to redirected data between files
Pipes
Work with many commands at the same time
Background Processing
Jobs/Tasks can be executed in the background with minimal interaction from the user
14
Features Of Unix
Communication
Unix has commands through which communication between different users connected to the system is possible
Shells
Unix has different types of shells like Bourne Shell(sh), Bourn Again Shell(bash), Korn Shell(ksh) etc
15
System Architecture
Major components of Unix are :
Kernel
Acts like a resource manager Allocates resources among its users in an optimal manner
Shell
Provides a processing environment for the user programs and acts like a command translator
Utilities
Programs which are used for development purposes
User Applications
Programs written by the user
16
System Architecture
User
SHELL
OTHER APPLICATIONS
User
SHELL
UNIX
COMMANDS
HARDWARE
DATABASE
PACKAGES
KERNEL
COMPILERS
SHELL
SHELL
User
User
17
18
Super block
Has the state of the file system-its size, status of the free space on the file system, how many files it can store etc
Inode block
It follows the super block-Gives the internal representation of the file
Data Block
Contains data.(Size of blocks can vary from 512 bytes to 4K)
19
Direct 1
Data Block
. . .
Data Block
Direct 9 Single Indirect Double Indirect Data Block Triple Indirect Array of 13 pointers Index Block Index Block Index Block Data Block
Data Block
Index Block
Index Block
Index Block
20
home bin sh
dev ls tty lp
etc
tmp
lib
usr
passwd shadow
Note: Different variants of UNIX differ slightly in the file system structure. But some of the basic folders are still the same.
21
The Relative Pathname. The pathname relative to current working directory. Example: training/vaniv.
Note : .. . : Parent Directory : Current Working Directory
22
Notes: 1. Option is generally preceded by (hyphen) symbol 2. More than one option can be used together
24
Types of Commands
Internal Commands
These are shell built-ins, not stored as separate files The shell does not generate a process for these commands and executes them directly. Examples: cd, echo
External Commands
These are stored as files having an independent existence The shell creates a process for these commands Examples: cat, ls
Shell Scripts
The shell executes these scripts by spawning another shell The child shell becomes the parent of the commands that feature in the script The child shell executes the commands in the script
25
Categories of Commands/Utilities
General Commands
Compression Utilities
Find Utility
26
Description
Clears the terminal screen Displays system date and time Displays calendar Displays the details of the users currently logged in Tells about the type of the command Used to create alias of an existing command Prints current working directory
27
Syntax
$ clear $ date [+Format] $ cal [arguments]
who
type alias pwd
$ who [arguments]
$ type cmd_name $ alias [alias_name=cmd_name] $ pwd
28
man command
A screenshot of the man command.
Syntax: man <command name>
[ ] indicates optional content
touch
$ touch file1 [file2 ] $ cat > file_name $ cat file_name $ cat >> file_name $ file file_name/dir_name $ more file_name
30
rmdir
$ rmdir dir_name
31
32
$ cp r dir1 dir2
mv
$ mv source target
Variations
Rename source file name with target name $ mv file1 file2 Move source file(s) in target directory If dir2 is not present: Rename dir1 with name dir2 if dir2 is present: Move sub-tree structure rooted at dir1 in dir2
$ mv dir1 dir2
$ mv dir1 dir2
34
35
S No. Hard Link 1 Inode number is same for the original and link file Link will remain valid even if we are deleting the original file Cannot be established for directories For every hard link created, value of the link field is incremented by 1 for original as well as link file
36
Soft link Inode number is different for the original and link file Link will not remain valid if we are deleting the original file Can be established for directories The link field value would be 1 for link file and no change in link field value of original file
2
3 4
37
Keyboard
stdin
stdout Monitor
stderr
Operating System
39
Standard Files
Standard Input (0)
This file is opened by shell to accept data
40
Pipes
Output of one program/command is piped as input to another program/command.
41
Special Files
/dev/tty
It is used to display on the terminal
/dev/null
This file is used to suppress the output from being displayed
42
43
Summary
Features of Unix Unix System Architecture General Unix commands File and directory related commands Shell meta characters Standard files Redirection and Pipe
45
Thank You
46