Вы находитесь на странице: 1из 37

Fundamentals of UNIX

Click to add text

UNIX Basics Definition , History, Architecture
Various flavors, Design Principles UNIX System Processes File System Types of Files Types of Shells Basic UNIX Commands

What is UNIX ?
Multi User, Multi Tasking, Multi Processing, Time Sharing, Portable, Networking, Strong Security (Secure) Operating System

Powerful Operating System

Written in High Level Language Hierarchical Directory Structure Supports internet

How the Name UNIX appeared ?

Bell Labs + GE + MIT


MULTICS(MULTiplexed Information & Computing Service)

Bell Labs Ken Thompson along with Dennis Ritchie 1969

UNICS( UNiplexed Information & Computing Service )

Bell Labs Brian Kernighan



History of UNIX

First developed

Ken Thompson & Dennis Ritchie, Research Group at Bell Laboratories

Version Version

1, 2 - Assembly Language. 3 - C Language, Bell Labs

History of UNIX Versions

UNIX Flavors
Sun Solaris 10 HP-UX 11i v3

Santa Cruz Operation (SCO)

LINUX AIX (Advanced Interactive eXecutive )(IBM) MINIX XENIX

General UNIX Architecture

UNIX Commands & Interface System Call Libraries





User Applications
SHELLs ksh, sh, csh etc.

What is Kernel ?
Internal Algorithms + System Calls Interacts directly with the Hardware
Provides File system, CPU scheduling, Memory management, and other OS functions like :
schedules tasks manages data/file access and storage enforces security mechanisms performs all hardware access

Provides services to user requests by interacting with Hardware.

Unix Design Principles

Everything treated as File & Process (Imp. Components) e.g. Terminal treated as a file /dev/tty1 A job when run treated as series of running Process User interacts with the KERNEL through SHELL(K Shell, C Shell, Bourne Shell etc.) Multi Processing System One process creates new process etc., distribute processes to CPUs Ability to increase priority of a Process, kill process etc. Can Submit a job (Script) in foreground (Default) or background. Most people survive on a Small handful of UNIX Commands

What is a Process ?
Fundamental to almost all operating systems = program in execution Has usually separate address space
It is an instance of a running program.

Processes in Windows
Windows Task Manager

in Windows NT / Windows XP/ Windows 2000 /

Process Creation
Processes are created during:
system initialization (Init, Swapper etc.) by another process user request (from shell) Batch job (timed, Unix at or cron) Foreground processes interact with user - The output would be redirected to the screen/terminal. Background processes (daemons) - Any process/command can be run in the background by using & at the end. Meanwhile, other processes can be run.

UNIX Processes
/home/ginger>ps -ef|more
UID PID PPID C STIME TTY TIME CMD root root root root 0 1 2 3 0 0 08:09:31 0 0 08:09:31 0 0 08:09:31 0 2 08:09:31 1 0 08:13:53 ? 0:38 sched ? 0:02 /etc/init ? 0:00 pageout ? 08:49 fsflush ? ? ? 0:00 /usr/lib/saf/sac -t 300 0:00 htt_server -port 9010 -syslog -message_locale C 0:00 ./ns-admin -d /apps/suitespot/3.62/admin-serv/config

Each process is identified by a number called Process Identifier (PID) PPID stands for Parent of the Process

root 2262

root 988 986 0 08:11:31 root 1078 1 0 08:11:35



1 0 08:09:35
1 0 08:09:36 1 0 08:10:41 1 0 08:11:36 1 0 08:10:02 1 0 08:10:29

? ? ? ? ? ?

0:00 /platform/SUNW,Sun-Fire-15000/lib/cvcd
0:06 vxconfigd -m boot 0:00 /usr/platform/SUNW,Sun-Fire-15000/lib/sckmd 0:01 /usr/sbin/auditd 0:00 /usr/lib/sysevent/syseventd 0:01 /usr/lib/picl/picld 2:40 /usr/lib/autofs/automountd

root 825 root 1196 root 76

root 598

root 879 876 0 08:10:48

UNIX File Hierarchy

/ (Root)

bin sbin







UNIX File Hierarchy

UNIX Directories with the information it contains bin all binaries, compilers etc.

dev all device files

etc all sys adm files, commands lib all library files stand all apis tmp all temp files

usr all user related files

Types of files
Ordinary file (data file, text file etc.) Directory (also treated as file) Device file Link File Sticky bit file

What is a Shell ?

User Shell UNIX O.S. (Kernel)

An Interface between User & Kernel An environment for a Script/command provided to the user to run/execute commands.

Broadly used Types of Shells:

1. K Shell /bin/ksh (Largest)
2. C Shell /bin/csh 3. Bourne Shell /bin/sh

UNIX Variables( Script Variables)

Variables are a way of passing information from the shell to programs when you run them

Variables SYSTEM Variables / Environmental Variables


USERDEFINED Variables i=10 v_string=jpmorganchase ONLY String text needs to be enclosed

Identify Shell I am working with (using SYSTEM Variable)

$echo $SHELL
/bin/ksh => K Shell /bin/sh => Bourne Shell /bin/csh => C Shell

Switch to a Particular Shell

1. K Shell to Bourne Shell $/bin/sh 2. K Shell to C Shell $/bin/csh

What is a UNIX Command ?

Binary file that resides in /usr/bin, /usr/local/bin or /bin directory What happens when executed ? When executed by user/through program, sends the user request to KERNEL that understands what request is made and provides services to the User command.

UNIX Commands
Connect to a UNIX Machine $telnet <Server Name | IP Address >

Prompts for login & password, after successful authentication, displays $ prompt.
To find out in which path (directory path) I am right now $pwd Present Working directory To find out the OS you are working in Uname

UNIX Commands
HOME Directory: This is the directory along with its path that appears whenever we login to a Unix Machine by entering right login/passwd and $ prompt is displayed. The directory along with its path can be found by using the command pwd This Directory Path is stored in SYSTEM Variable HOME. List all files and subdirectories in Ascending order of file creation ie., latest file created present at the last line $ls lrt

By default a File has a Read and Write permission but no execute permission unlike a Directory.

UNIX Commands
To see the help / manual of a UNIX Command
man <CommandName> $man ls To print the system date and time $date

To create a NEW directory $mkdir dir1

To change from one directory to another existing directory
$cd <Existing directory with its PATH> eg. cd dir1

To create a new empty file - $touch <Filename>

To Create a new file or a shell script, use VI editor

Display the contents of a file at Command Prompt.

cat <filename> $cat test.txt To find the no. of lines, chars, words in a file wc <filename> $wc test.txt To change the Name of an existing file $mv file1 file1.sh

UNIX Commands

To remove a file from a directory and place it in a new directory $mkdir new_dir #First creating the NEW directory $mv file1 ./new_dir

UNIX Commands
To have a back-up of an i) existing file $cp file1 file1.bak ii) existing directory (with files in it) $mkdir backup_dir $cp log.* /backup_dir File Permissions - Categorized for 3 types of Users 1) User (Owner) u the person who is able to login successfully and is creating the file. 2) Group g the group to which the user belongs to

3) Other o All other users

UNIX Commands
To give Write Permission for the file. $chmod u+w ScriptFile

To give eXecute permissions to a file (Shell Script) inorder to run the file.
$chmod u+x ScriptFile To Remove Write Permission from the file. $chmod u-w ScriptFile To Remove eXecute permissions from a file (Shell Script).

$chmod u-x ScriptFile

UNIX Commands
To Check whether an Application/Script process is Running $ps ef|grep <Name of the Script File that was executed>

Where e show processes of ALL Users.

f - show FULL ie., process IDs & PPIDs
Kill an active running process

1. Obtain the Process ID of the process $ps ef|grep <Application> 2. Kill the Process by using its Process ID obtained from above. $kill -9 <Process ID>

UNIX Commands
To have a tree view of the processes running for an Script/job that is run. 1. Obtain the Process ID of the process

$ps ef|grep <Application>

2. Use ptree command for the Process ID obtained from above. $ptree <Process ID>
To Search for a pattern (a word) in a file and display the record.

grep <pattern> <filename> $grep error 20061118.log Here we are searching for the occurrence of error by using keyword error in the log file.

UNIX Commands
Search irrespective of CASE sensitivity (UPPER/LOWER case) of the pattern to be searched. $grep i error 20061118.log In the Current Directory, to search for a pattern when file name is not known $grep il error *.log To search for errors and warning appearing in a Log file $egrep i error|warn 20061118.log

UNIX Commands
To display list of ONLY directories $ls lrt|grep ^d

To view a Growing Log file

$tail f <Logfilename>


Common Discussions / Questions

Thank U