The document provides information about the UNIX operating system. It discusses key UNIX concepts like the kernel, shells, utilities, file system structure, permissions, processes and signals. It describes how the kernel acts as an interface between hardware and applications, and how shells allow users to run commands and utilities. It also outlines the typical directory structure and basic file management commands in UNIX.
1. UNIX (UNICS)
[UNiformed Information and Computational language]
Operating system:
Interface between hardware and user through applications.
Only OS can interact with hardware directly.
Applications:
Start menu - .dll
Calculator - .exe
user Applications / GUI OS Hardware
Programming languages: (Language used to write programs)
Low (Machine language):
o Binary coded
o E.g.: ADD A,B ; MOV A,B
Medium (Assembly language):
o OS(system) can easily convert it to machine language directly
o Short commands
o E.g. :A+B
High:
o OS(system) cannot interpret high language
o Requires interpreter to be converted to machine language
o E.g.: C, C++, JAVA, etc.
UNIX features:
Portable, multitasking, multiuser OS
Developed in 1969 by group of AT&T employees at BELL labs, including Ken Thompson,
Dennis Ritchie, Brian Kernighan, Douglas Mcllroy and Joe Ossanna.
Initially developed in assembly language but later on recorded entirely in C language.
UNIX System V:
Abbreviated: SysV
1st commercial version of UNIX OS
Release SVR4 in 1991
Incorporated elements od BSD and SunOS into System V
2. UNIX Standards: [All standards belong to POSIX]
1980s: Motivation
1998: POSIX
1990s: Spec 1170
1997 : Single UNIX Specification version 2
2001 : POSIX:2001, Single UNIX Specification version 3
2004 : POSIX:2004
2008 : POSIX:2008
UNIX Components:
Computer hardware
UNIX Kernel:
o System booted â Kernel loaded
o 1OS 1UNIX kernel Multiple users
o Connection between hardware and shells
The shell:
o 1Shell 1User
o Connection between Kernel and applications / utilities
Utilities and application programs
Utilities &
Application programs
The Shell
UNIX Kernel
Computer
Hardwar
e
UNIX components / computer hardware for UNIX
3. LOG Process/ Shell creation:
Daemon:
Background processes which becomes active when system boots up till the time when
system shuts down
Take large memory, power and CPU usage
Fork:
Duplicating/ parallel processing
If forked element dies, the one creating it still lives
Spawn / exec:
Creating from within self
Child creation
If parent dies, the child also dies.
init
fork
init getty login shell
exec/ exec/ exec/
spawn spawn spawn
fork
shell
Log process / Shell creation
Process:
inits are the daemons of UNIX system.
For the log in process, init forks another init (one for every terminal/ login /user)
This forked init further spawns/exec onegetty
This getty further spawns/exec one login
4. This login is nothing but GUI displaying the page for Login ID and password. It compares
the entered details of login ID and password with the authenticated ID and passwords
saved in files.
If ID and password matches, then login spawns/exec one shell, else getty and login
processes terminates and goes back to init process.
This shell interacts with application to do further process. It can also fork other shells for
doing parallel processing of more than one applications/utilities.
Once the user logs out, forked init dies causing the entire getty,login,shell,forked shells to
die (as they are childs).
Shell prompts:
Successful login is indicated by appearance of shell prompts or system prompts on the
terminal.
List of default prompts are:
Sr. No. Prompts Shells
1 $ (dollar) Bourne &Korn shells (sh, bash &ksh)
2 % (percent) C shells (csh&tcsh)
3 # (hash) Any shell as root [admin login]
Commands in UNIX:
Commands are instructions/programs written to perform specific action
Lower cased and cryptic
Have arguments (-), format specifiers (+) & options
Can use 2dary prompt (>) [command more than one line]
Killed using <delete> or <ctrl-u>
Types:
o External (commands in files which shell doesnât recognize) &
o Internal (Shell commands)
Basic UNIX commands:
echo
uname
who
who am i
date
cal
cat
spell
man
5. Note:
> : insertion / overwriting
>> : appending
ctrl+z : exiting the file
q : coming out of editor
exit : logout as well as closing putty window
H.W.:
Types of kernel
Generation of computers
File system of UNIX OS
Commands description
File system:
File: store information
Directory: Special kind of file which stores other files and directories
File system: System made up of files and directories
/
bin dev home lib temp sbin etc usr var
dsk fdd lpo bin sbin lib local
romeo juliet
progs Login.sql .profile
File System
Static inbuilt folders:
6. /(root):
bin: Binary executables (shell software and UNIX commands)
dev: device files necessary for hardware configuration i.e to operate peripherals like printers and
terminal
home:user folders
lib:
temp: temporary files and folder becomes empty when rebooted
sbin: Self binary executables which start and stop by themselves
etc:
usr:
var: files and folders with variable information e.g. help file, root path to printer, file links
Note: Rest folders are variable
Path names:
Route taken to reach a file in the file system is known as path to that file
Depending on beginning point from where path is defined, there are two types of path
names:
o Absolute path name: Beginning from root
o Relative path name: Beginning from present working directory (PWD)
Wild-cards:
Characters such as ?, *, [], ! have special meaning attached to them in regard to pattern matching.
They are called wild-cards or Meta-characters.
*- zero or one or many
? - exactly one character
[]- character class (forward order only)
! - Bang character (not, negating)
Note: echo* --- list files and directories (similar to ls [not hidden ones])
File and directory commands:
7. Sr. No. Command Explanation
1. ls : Lists file and directories
ls -a All files and directories including the hidden ones
ls -A All files and directories excluding .& ..
2. wc Lines, words, characters count
wc âl Lines count
wc âm Character count
wc âc Bytes count (similar to character count :wc -m)
wc âw Words count
wc âL Maximum line length
3. mkdir Make a directory
4. cd directory Change to named directory (if exists)
5. cd Change to home directory
6. cd~ Change to home directory
7. cd.. Change o parent directory
8. cp file1 file2 Copy file1 and call it file2 (duplicate)
cp âr dir1 dir2 Copy recursively all files and directories from dir1 to dir2
(duplicate)
9. mv file1 file2 Move(different) or rename(same directory) file1 to file2
mv dir1 dir2 Move(different parent) or rename(same parent directory) file1
to file2
10. rm Remove file
rm * Remove all files
11. rmdir Remove directory (only when empty)
12. cat file Display a file
13. less file Display a file, one page at time
14. head file Display first few lines of file
15. tail file Display last few lines of file
16. ln : Link creation
ln file1 file2 Hard link file2 of file1 (file2 linked to content of file1) [file1
ln âs file1 file2 deleted : link exists]
Soft link file2 of file1 (file2 linked to file1)[file1 deleted : link
broken]
17. grep âkeywordâ file Search a file for keyword [displays sentence in which word
appears]
File attributes and permission:
8. Owner (u-user)
Group (g) (a)
All
All others (o-others)
File attributes:
Name
Creation
Size
Owner
Group to which owner belongs to
Link information
Permissions
inode number (where meta data is stored)
Note: Every file has inode block (meta data-data of data) and data block
File type:
d (directory)
l (symbolic link)
b (block special file)
c (character special file)
p (named pipe special file)
s (local socket special file)
Note:
socket: Port
Piping: Deals with inter-process communication i.e. input and output of one program are
related to input and output of other program
File Permissions: permission
owner (u) group (g) other (o)
rwx rwx rwx
9. Reading (r)
Writing (w)
Execution (x)
File access commands:
Sr. No. Command Explanation
1. ls: Long listing format
ls â a All files and directories
ls -al Al visible as well as hidden files and directories
2. chmod Change file permission
3. chgrp Change file ownership
4. chown Change group of file
5. file Identify type of file based on their content
Examples:
ls:
ls âl
total 4 [block of data]
[permission user group size date time file/dir name]
drwxrwxrw- user6 user61023 2 may 2012 1:30 pm keviniti1
-rw-r--r-- user6 user6 3232 1 may 2012 10:44 pm niti.txt
file:
file niti.txt
niti.txt : ASCII text
chmod:
o chmod 655 niti.txt [octal representation / assignment]
o chmod u=rw, go=rx [full assignment â previous rites dropped]
o chmoda+r, u+w, go+x [partial assignment â added to previous rites ]
ls âl
-rw-r-xr-x user6 user6 3232 1 may 2012 10:44 pm niti.txt
[only present owner can do so i.e. user6]
chown:
chown user1 niti.txt
[only present owner can do so i.e. user6]
chgrp:
chgrp user1 niti.txt
[only present owner can do so i.e. user6]
Pipe and piping
10. Pipe: Data
Piping: Process on intercommunication between commands. In this output of one
command is taken as input to other command. (original source and destinations are
altered)
command1 command2
output of command1 input to command2
Piping
Redirection (Input, Output, Error):
Redirection: Altering the source and destination
Input redirection: Keyboard is the standard input. Instead of keyboard, if input is taken
from a file, then it is called input redirection. All commands cannot be made to do input
redirection. Only those commands, which accept input from keyboard, can be redirected.
e.g. < or 0<, etc.
Output redirection: Display screen is the standard output. Generally when program is made
to execute, its output goes to standard shell prompt output i.e. display screen. Instead of
display screen, if output is made to go somewhere else like file, printer, disappear or other
command, then it is known as output redirection.
e.g. 1> or >, 1>> or >>, | (piping), etc.
Error redirection: Display screen is the standard error output. Generally when program is
executed and errors are not required to be displayed or required to be stored somewhere
temporarily, then it can be redirected to file. This is known as error redirection. %
e.g. 2>, 2>>, etc.
Redirection:
11. Sr. Redirection Description Examples
No. symbols
1. < Input redirection wc niti.txt
wc<niti.txt
2. > Output redirection wc< niti.txt > output.txt
who> filename
3. >> Output redirection with appending cat>> niti.txt
4. | Output of one command as input to other who | wc âl
command who | grep âuser6â
Filters:
Program that gets most of its data from its standard input (main input stream) and write its
main result / output into its standard output (main output stream).
Inputs should be greater than or equal to outputs
UNIX filters are used as elements of pipelines
E.g.s: grep, wc, cat, tee, head, tail, cut, sort, uniq, awk, sed, etc
Process:
Program (set of instructions) in action / execution is known as process.
Kernel is the main process (in process hierarchy). It generates or spawns other processes.
Each process has unique id called process identity (PID).
Maximum number of PID is 32767.
Process is responsible for creating other processes, which becomes its child.
Types of processes:
Interactive of foreground processes:
o Act upon user directories
o Normally attached to terminal
Non-interactive or background processes:
o Runs independent of terminal
Daemons:
o Comes into existence as soon as system boots up and will be alive till system is shut
down
o Cannot kill these processes prematurely
o Its combination of foreground and background processes
o Only admin can interact (direct / redirect) with daemons but they cannot stop them
Running command in background:
12. Command is made to run in background by terminating it with an amperes and (&)
symbol.e.g. who | sort âr >user.lst
The shell immediately returns the PID as well as shell prompt ($)
The user can find the process status using the PID.
As soon as background process is completed, output pops out and mixes with the
foreground processes. Hence it is recommended to redirect the output to a file.
Process attributes:
Sr. no. Process attributes Description
1. PID Process identification number
2. TTY Terminal type
3. TIME Cumulative time
4. CMD Command
5. UID User ID
6. PPID Parent PID
7. STIME Starting time
8. C CPU time consumed
âpsâ command:
Displays attributes of processes that are currently running
o âf : full list
o âa : all users
o âu : user
o ât : terminal
o âe : every thing (default)
âniceâ command: [only by admin]
All processes in UNIX have equal priority.
Process priority:
o UNIX: 0(highest) to 39(lowest-default)
o LINUX: -19(highest) to +20(lowest-default)
Users can decrease the priority but cannot increase them (only admins can increase
priority)
E.g. nice -19
LINUX: 20+(19)=39
E.g. nice - -19
LINUX: 20+(-19)=1
Signals:
13. Messages(signals) are sent to process in one of the following occasions:
Under error condition or user interrupt, the kernel generates the signal
During inter process communication, the participating process generates these signals
Types of signals
Sr. No. Signal no. Name Function
1. 1 SIGHUP Hangup
2. 2 SIGINT Interruupt
3. 3 SIGQUIT Quit
4. 9 SIGKILL Sure kill
5. 15 SIGTERM s/w termination
6. 24 SIGSTOP Stop
âtrap commandâ:
Traps are one or more signals to decide further course if action.
Syntax: trap [commands] signal_numbers
E.g.: trap âexitâ 2 3 15
To reset: trap 2 3 15
âkillâ command: [only by admin]
Terminating a process prematurely is called killing. This can be done with DEL or BREAK
key.
To kill background process, kill command is used.
Syntax: kill PID
Sr. No. Shortcut Description Signal
1. ctrl + c User interrupt Signal 2
2. ctrl + Sure kill Signal 9
3. ctrl + z Stop Signal 24