Sie sind auf Seite 1von 43

2007, Cognizant Technology Solutions. All Rights Reserved.

The information contained herein is subject to change without notice.


C3: Protected C3: Protected
Introduction to Unix
and Basic Concepts
Basic
2
About the Author
All have 6 years of experience in UNIX Credential
Information:
UNIX/PPT/1007/1.1 Version and
Date:
A. Senthil Kumar (162298); P,S Nayana (131085); A.
Karthikeyan (153306)
Created By:
3
Icons Used
Questions
Contacts
Reference
Demonstration
Hands on
Exercise
Coding
Standards
Test Your
Understanding
Tools
A Welcome
Break
4
Introduction:
This chapter talks about the introduction of Unix,
History, UNIX OS Structure, File System, File
Permission
Introduction to Unix and Basic
Concepts: Overview
5
Objective:
After completing this chapter, you will be able to:
Explain the basic background in UNIX structure
Define kernel
Describe the history of UNIX
Work with file systems
Define file permissions
Work with file permissions
Introduction to Unix and Basic
Concepts: Objective
6
UNIX: Overview
What is Unix:
A fully-networked 32/64-Bit Operating System
Multi-user, Multitasking, and Multiprocessor
Has the X Windows GUI
Coexists with other Operating Systems
Runs on multiple platforms
Includes the Source Code
7
UNIX Features
Features:
Multi-user system:
Enables multiple users to share system resources
Uses time slicing
Multitasking:
Performs multiple tasks concurrently
Background and Foreground jobs
Portability:
Ability to operate on a different hardware with
minimum changes
Entire OS can be moved with its File System, Utilities
and Application since it is written in a high level
language - C
8
Objective:
1. To understand what is an operating system
2. Components of an operating system
3. Basic functions of an operating system
What is an operating system?
An operating system is a collection of programs that
coordinate the operation of computer hardware and
software.
Three basic components:
The Kernel
The File System
The Shell
UNIX as a Operating System:
Overview
9
Basic functions of an operating system are:
Opening files
Reading files
Closing files
Creating files and/or directories
Copying or deleting files and directories
Memory management
Network communication
Reading and writing to devices
Allowing or limiting access to system resources
Monitoring/Killing processes
UNIX as a Operating System:
Overview (Contd.)
10
What is Kernel
Kernel:
The innermost layer is the hardware that provides
the services for the OS
Kernel interacts directly with the hardware and
provides the services to the user programs
User programs interact with the kernel through a set
of standard system calls
There is only one kernel for any system
It is loaded into memory when the UNIX system
boots
Keeps users and processes separate in multi-user
and multi-tasking environment
Manages system resources
Allocates time between users and processes
11
What is Kernel (Contd.)
Decides process priorities
Manages Memory and allocates it to each process
Schedules work done by the CPU
Organizes transfer of data from one part of machine
to another
Accepts instructions from Shell and caries them out
Enforces access permission on the file system
Well written user programs are independent of the
underlying hardware, making them readily portable
to new systems.
Located at /UNIX or /kernel.
12
Phase I:
Initially used among the scientific, engineering and
academic communities due to its:
Multi-user and Multi-tasking environment
Flexibility and portability
Electronic mail
Networking capabilities
Phase II:
It has also gained widespread acceptance in
government and business organizations where it
became the OS of choice due to its robustness
UNIX as a Operating System:
Evolution
13
UNIX as a Operating System:
Evolution (Contd.)
Phase III:
Internet - most servers are UNIX servers. The Web
owes much of its origin to the inspiring work done by
the UNIX community.
Phase IV:
Linux - the preferred OS for the future? Created by
Linus Torwalds, Linux has today moved from college
campuses to commercial world and is giving the
competition a run for its money.
14
History
Invented by Ken Thompson at AT&T in 1969
First version written in assembly language:
Single user system, no network capability
Thompson, Dennis Ritchie, Brian Kernighan:
Rewrote Unix in C: processor/architecture
independent
Unix evolution:
i. Bell Labs, USL, Novell, SCO
ii. AIX, Ultrix, Irix, Solaris,
iii. BSD, FreeBSD, Mach, OS X
iv. Linux, Redhat, Suse,
15
UNIX Operating System Structure
Users
Application Programs
Kernel
Shell
Hardware
16
Q & A
Allow time for questions from participants
17
Getting Started: Logging In
Login and password prompt to log in
login is users unique name
password is changeable; known only to user,
not to system staff
Unix is case sensitive
Issued login and password (usually in lower
case)
#su command is used for switching between
users:
#su - <username>
18
Exiting and Terminal Type
^C - interrupt
^D - can log a user off; frequently disabled
Logout - leave the system
Exit - leave the shell
Terminal type:
Default is often to prompt the user, for example,
vt100, xterm, or sun
19
Introduction: File System
What is file system?
The abstraction used by kernel to represent and
organize the storage resources.
UNIX file system:
Is organized in tree structure.
File tree can be arbitrarily deep.
File name must NOT LONGER than 256 chars.
Single path name must NOT LONGER than 1023
chars.
20
File System Structure
21
/ The root directory.
/bin or / sbin Commands for basic
system operation.
/ dev Device entries.
/etc Critical startup and
configuration files.
/lib Library for the C
compiler.
/ tmp Temporary files.
/ var/ adm or / var/log Accounting file, log
Files.
Organizing of the File System
(Contd.)
22
Types of Files
Regular files:
Binary:
GIF, JPEG, Executable, and so on.
Text:
Scripts, program source code, and documentation
Supports sequential and random access
23
Types of Files (Contd.)
Directory:
Can contain ANY kind of files
what is . and ..??
Device File:
Allows programs to communicate with hardware.
Kernel modules handles device management.
There are two types of Device Files:
Character Device
Accepts a stream of characters, without regard to
any block structure.
It is not addressable, therefore no seek operation
Block Device
Information stored in fixed-sized block
It is addressable, therefore seek operation is
possible
24
Types of Files (Contd.)
UNIX Domain Sockets (BSD):
Sockets that are local to a particular host and are
referenced through a file system object rather than a
network port.
X windows
Named Pipe
Allow processes to communicate with each other.
25
Types of Files (Contd.)
Hard links:
Linking files by reference
System maintains a count of the number of links
Does not work across file systems
Soft links:
Linking files by name
No counter is maintained
Work across file system
26
File System
INODES:
Kernel maintains file information in a structure called
inode
Creation and modification time stamps
Ownership, file size, and so on
Commonly used INODE information can be found by
using ls command
Group information and be modified by using chgrp
command
27
I-node
28
Unix File System
Each disk partition has 4 Regions:
block 0: boot block
block 1: super block. Contains the size of the disk and the
boundaries of the other regions
i-nodes: list of i-nodes, each is a 64-byte structure
free storage blocks for the contents of files.
Each i-node contains owner, protection bits, size,
directory/file, and 13 disk addresses.
The first 10 of these addresses point directly at the first 10
blocks of a file. If a file is larger than 10 blocks (5,120 bytes),
the 11th points at a block for secondary indexing single
indirect block
29
Unix File System (Contd.)
Second-level index block contains the addresses of the next
128 blocks of the file (70,656 bytes)
Two levels of indirection: 12th entry (double indirect block)
points at up to 128 blocks, each pointing to 128 blocks of the
file (8,459,264 bytes)
Three levels of indirection: 13th address (triple indirect block)
is for a three layered indexing of 1,082,201,087 bytes.
A directory is accessed exactly as an ordinary file. It contains
16 byte entries consisting of a 14-byte name and an i-number
(index or ID of an i-node). The root of the file system
hierarchy is at a known i-number (2).
30
Creating File System
Mounting file system:
File tree is composed of file system
Use mount command to map a directory within the
existing file tree (mount point) to the root of the new
file system.
mount /dev/hda2 /usr
Use umount command to detach the file system:
Detaching will fail if the file system is busy.
31
Creating a New file and Directory
Creating a new file
touch <newfilename>
Creating a directory:
Mkdir <dirname> ia the Command to create a
directory.
Example: mkdir /home/ramesh/data
Common options:
-p create the intermediate (parent) directories, as
needed.
-m mode access permissions
32
File Permissions
Read (r): A user who has read permission for a file may
look at its contents or make a copy of it. For a directory,
read permission enables a user to find out what files are
in that directory.
Write (w): A user who has write permission for a file
can alter or remove the contents of that file. For a
directory, the user can create and delete files in that
directory.
Execute (x): A user who has execute permission for a
file can cause the contents of that file to be executed
(provided that it is executable). For a directory, execute
permission allows a user to change to that directory.
33
File Permissions (Contd.)
Access Control Level:
d rwx r-x r-:
Each file, directory, and executable has permissions set for
who can read, write, and/or execute it. To find the
permissions assigned to a file, the ls command with the -l
option should be used.
Also, using the -g option with "ls -l" will help when it is
necessary to know the group for which the permissions are
set.
The various file modes are:
- Regular file (as mode)
d Directory
l Symbolic link
- no permission
r read
w write
x execute
34
File Permissions (Contd.)
d rwx r-x r-:
The next 9 characters are in 3 sets of 3 characters
each. They indicate file access permissions.
The first 3 characters refer to the permissions for the
user
The next three for the users in the UNIX group
assigned to the file
And the last 3 to the permissions for other users on the
system
Each of the permission types is represented by either a
numeric equivalent:
read=4, write=2, execute=1
or a single letter:
read=r, write=w, execute=x
35
File Permissions (Contd.)
d rwx r-x r--
Absolute value : 764
User group others
r w x r w x r w x
( 4 + 2 + 1 ) (4 + 2 + 0) (4 + 0 + 0 )
= 7 = 6 = 4
Symbolic to Octal Conversions:
SYMBOLIC BINARY OCTAL
--- 000 0
--x 001 1
-w- 010 2
-wx 011 3
r-- 100 4
r-x 101 5
rw- 110 6
rwx 111 7
36
File Permissions (Contd.)
Changing Access - chown
chown:
Ownership of a file can be changed with the chown
command. This can only be done by the super-user, A
normal user cant give away ownership of their files.
Example: chown trng datafile
Changing Access Chgrp
chgrp:
Anyone can change the group of files they own, to another
group they belong to, with the chgrp command.
Example: chgrp trngroup datafile
37
File Permissions (Contd.)
Changing Access chmod:
The command to change permissions on an item (file,
directory, and so on) is chmod
chmod [u|g|o|a] [+|-|=] [r|w|x] [file]
chmod 755 [file]
Example:
chmod u=rwx, go=rx datafile or chmod 766
datafile
Symbols used for user category:
u users
g group
o others
a all
The operator can be:
+ add permissions
- remove permissions
= set permissions
38
Allow time for questions from participants
Q & A
39
1. What are the basic components of an operating
system?
2. What is meant by file system?
3. Multiple Kernels can run in a system - state true or
false.
4. Which file mode indicates a Symbolic Link?
5. Which type of Permission allows a user to change the
directory?
6. A file has got permission as 745. What will be the
permissions of User, Group, and Others?
7. Ownership of a file can be changed by any user. State
true or false.
Test Your Understanding
40
Practice Exercise
1. How do you list files in a directory?
2. How do you list all files in a directory, including the
hidden files?
3. How do you list all files in a directory, including the
hidden files?
4. How do you kill a process?
5. Create a new file using cat
6. Check File permissions for passwd file
7. Create a file and change the file permission as read-
only
41
An operating system is a collection of programs that
coordinate the operation of computer hardware and
software.
Kernel is the innermost layer is the hardware that
provides the services for the OS.
Kernel interacts directly with the hardware and provides
the services to the user programs.
The file permissions are: read, write, and execute.
All file system have this concept of file tree:
Transparent to user even mount point is mapped to a
remote file system.
Introduction to Unix and Basic
Concepts: Summary
42
www.redhat.com
www.cma.gov.cn
www.ee.surrey.ac.uk/Teaching/Unix/
Disclaimer: Parts of the content of this course is based on the materials available from the Web sites
and books listed above. The materials that can be accessed from linked sites are not maintained by
Cognizant Academy and we are not responsible for the contents thereof. All trademarks, service marks,
and trade names in this course are the marks of the respective owner(s).
Introduction to Unix and Basic
Concepts: Source
2007, Cognizant Technology Solutions. All Rights Reserved.
The information contained herein is subject to change without notice.
You have successfully
completed
Introduction to Unix and
Basic Concepts.

Das könnte Ihnen auch gefallen