UNIX
FUNDAMENTALS
By - Sarvesh Kumar Gupta
Agenda…
History Of Unix
Features of Unix
Unix System Organization
Unix File System
Commands
VI Editor
History Of Unix
UNIX was first developed in1965 by Bell Telephone Labs and
GE Company
Initially, UNIX was named MULTICS
Dennis Ritchie and Ken Thompson of AT&T started afresh in
1969 and developed on PDP-7
The system was named UNIX by Brian Kernighan
History Of Unix
In 1971, UNIX was ported on PDP-11 (16 bit)
This flavor was developed on Assembler and system dependent
To Handle this, Ken developed ‘B’ language
But, ‘B’ has some deficiencies
Ritchie modified ‘B’ and developed ‘C’
The whole UNIX was written in ‘C’ except some modules
Evolution continued…
1975 (UCB) Berkeley developments starts
1980 Xenix by Microsoft
1982 HPUX was introduced
1991 Linus Trovalds creates LINUX kernel
1999 Red Hat Inc. release Red Hat Linux version6.0
NOW Two major standards of UNIX are in market
SysV(AT&T) release and BSD release
Prominent Unix flavors !!!
BSD: Berkeley, BSD
Solaris: Sun Microsystems, Sys 5/BSD
Ultrix: Digital Equipment Corporation, BSD
OSF 1: Digital Equipment Corporation, BSD/sys 5
HPUX: Hewlett-Packard, Sys 5 /BSD
AIX: IBM, Sys 5 / BSD .
IRIX: Silicon Graphics, Sys 5 .
GNU/Linux: GNU, BSD/POSIX
Minimum Hardware requirements
Minimum of 80 MB Hard disk space with 4 MB RAM
Any 80286 and above processor
UNIX requires about 1MB RAM space for each extra terminal
connected to it
Features of UNIX…
Multi-user Capability
Terminals are connected to the host (main machine) through
controller card
The controller card provides 4/8/16 ports
UNIX supports different terminals
Dumb Terminal
Terminal emulation (Using Emulation Software)
Dial-in Terminal (Using telephone to connect to host)
Features of UNIX…
Multitasking
UNIX is capable of carrying more than one job at a time
Do jobs in foreground and background
Achieved through dividing the CPU time intelligently among all
processes being carried-out
Features of UNIX…
Security
Allows sharing of data
Three levels of security
Login level security
File Security through permissions
File encryption utility
Features of UNIX…
Portability
Can be ported to any system with bare minimum modifications
This was achieved through C as UNIX was written in C
System Organization
Tools & Applications
Shell
Kernel
Users
Hardware
System Organization
Manned in three levels
Heart of UNIX is Kernel
Kernel interacts with hardware
Communication is carried out by the second layer, Shell. Shell is
a basic command interpreter
Third level is the User applications
Shells
There are many shells available on Unix
Bourne Shell (/bin/bash) or (/bin/sh)
C Shell (/bin/csh)
Korn Shell (/bin/ksh)
Restricted Bourne Shell(/bin/rsh)
Secured Bourne Shell (/bin/ssh)
Getting started
Logging to Unix
Access to Unix is through a login and a password
Login & password will be created by the System administrator
Password will not be visible while typing
After three successive failures of login, the login will be
disabled
If login/password or both not entered correctly, it returns a
message “login incorrect”
After Successful login, command prompt is displayed (# or $)
Behind the Logging ….
login/password
Checks the authenticity in /etc/passwd file
Executes .profile file which was created at the time of account
creation
Then, the command prompt is displayed
Logging Out !!!
This can be done by any of these three methods :
Press Ctrl +d
Type “exit” in the command prompt
Type “logout” in the command prompt
Unix File System
Unix understands everything as a file. It may be a disk or
terminal or directory or a file
All hardware devices are accessed through files
Files can be primarily categorized into three types :
Ordinary Files (represented by ‘-’ while listing)
Directory Files (represented by ‘d’ while listing)
Device Files (present in /dev)
File System Hierarchy
Commands
Ground Rules ::
All Unix commands should be entered in lower case letters
Commands may have arguments
Between command and arguments, there must be at least one
space or tab
All command flags will be given with ‘-’ (Hyphen)
Arguments can be clubbed into a single argument
Eg : ls –la
Commands
File manipulation commands
File Creating - touch , vi
File Viewing - cat, more, less, head , tail
File Listing - ls
File Linking - ln , ln –s
File removing - rm
File copying - cp
File renaming or moving – mv
Directory commands – cd, mkdir, rmdir
File permissions – chmod, chgrp, chown
Commands
touch file1 - creates an ordinary file ‘file1’
touch –a file1 - changes only the access time of ‘file1’
touch –m file1 - changes only the modification time
touch file1 file2 - creates two files ‘file1’ and file2’ of zero size
cat file1 - displays contents of ‘file1’
cat > file1 - whatever is typed after this will go into ‘file1’
cat >>file1 - whatever is typed after this will be appended
cat file1 file2 - displays the contents of ‘file1’ and ‘file2’
cat file1>file2 - ‘file2’ will be overwritten with contents of ‘file1’
cat file1>>file2 - contents of ‘file1’ will be appended to ‘file2’
Commands
cat file1 file2> file3 - ‘file3’ is overwritten with the contents
of ‘file1’ and ‘file2’
cat file1 file2>>file3 - contents of ‘file1’ and ‘file2’ are
appended to ‘file3’
more file1 - used to filter the file for CRT viewing
less file1 - similar to ‘more’. Enables forward as well as
backward movement
head -50 file1 - displays the first fifty lines of ‘file1’
head file1 - displays the first ten lines of ‘file1’
Commands
ls - list all files in current directory
ls –a - list all files including hidden
ls –l - long listing
ls –r - reverse order while sorting
ls –t - sort by modification time
ls –R - lists subdirectories recursively
ls –U - lists entries in directory order
ls dirname - lists all files in the directory
ls a* - lists all files starting with ‘a’
ls [a-c]* - lists all files starting with ‘a’,’b’ and ‘c’
Commands
ls –l gives something like this
total 32
-rwxr-x--x 1 usr1 group1 24 jan 06 10:13 file1
drwxr-x--x 1 usr1 group1 24 jan 06 10:13 file2
-rwxr-x--x 2 usr1 group1 24 jan 06 10:13 file3
total 32 means current directory occupied 32 blocks
Generally each block in UNIX is 1024
UNIX uses file types to distinguish files
Commands
This is the first - (hyphen) place in output
- : hyphen is ordinary file
d : directory file
c : character specific file like terminals
b : block specific file like hard disk
l : symbolic link
s : Semaphore
p : named pipe
m : shared memory file
Commands
The next 9 characters provides the information about file
permissions
Next column gives the number of links
Owner name
Group name
File size in bytes
Date & Time of last modified
Finally the file name
Owner concept comes with multi-user OS
The file creator is the owner by default
Group is formed with same type of users
Commands
The first 3 characters in permission field is owner permissions
The next 3 characters tells about the group permissions
Last 3 characters gives the other permissions
There are three types of permissions like
r - read permission
w - write permission
x - execution permission
rwxr-x--x means
Owner of this file has read, write and execute permissions
Group has read and execute permissions
Others has only execution permissions
Commands
Permissions can be encoded numerically
Read ( r ) - Weight 4
Write ( w ) - Weight 2
Execute ( x ) - Weight 1
The weight of Read+Write+Execution (rwx) is 4 + 2 + 1 = 7
The weight of Read+Execution (r-x) is 4 + 1 = 5
The weight of Write+Execution(-wx) is 2+1 = 3
Commands
Existing file permissions can be changed with the command
chmod
To change the rwxr-x--x (751) permissions to rwxrwxrwx (777)
permissions of file1 is
$chmod 777 file1
To give write permission to all
$chmod +w file1
To remove write permissions to all including the owner
$chmod -w file1
The above command is generally used to keep a file safe by
making it READ-ONLY
Commands
Default file creation permissions will be obtained from the umask
value
Mask of umask will give the actual permissions
Mask is subtract value from 7
If umask is 021, then the default file permissions are
7-0,7-2,7-1
i.e. 756 are the permissions (rwxr-xrw-)
754 are the most widely used permissions for a directory
Commands
To safeguard the directories from malicious intentions, sticky bit
may be added to the directory
Disables file deletion
Can be given by
$chmod +t dir-name
Sticky bit will be added at the end in the permission string
This has weight 1
To give both 754 & Sticky bit permissions in one command
$chmod 1754 dir-name
Only the owner & super-user can delete the files in this directory
If the sticky bit is on to a file, the file becomes memory resident
Commands
To know the free spaces in the UNIX, the df (disk free) command
can be used
$df
/(dev/root): 12500 blocks 27654 I-nodes
df gives the blocks of 512 bytes size
To know the disk usage, give:
$du
UNIX uses a variable called ulimit which controls the maximum
file size any user can create
This is to save the disk space misuse.
$ulimit
Commands
Stands for Calendar
Can print a calendar between year 1 to 9999
$cal 1960
Prints the whole calendar of 1960
$cal 4 1960
Prints only April month calendar of 1960
Prints the given string in big letters
$banner <string>
Used to know the file type like shell script, executable, etc
$file file-name
Commands
wc - Used to know the number of characters, number of files
and number of lines in a file
$wc file1
$wc -l file1
Displays the number of lines in file1
grep -Acronym for ‘Globally search a Regular Expression and
Print it’
Searches for a pattern in file(s)
$grep abc file1
Searches for the string ‘abc’ in file1
Commands
Link is an alias to a file.
Two types of links .
Hard and Soft.
Hard link
# ln file1 file2.
No separate file is created.
Cannot link directories.
Cannot link across file-systems.
To remove a file all links must be removed.
Commands
Soft/symbolic Link
# ln –s Old file New file
Can link directories.
Can link across file-systems.
Commands
rm - The file removed can not be recovered like in DOS using
undelete
Care should be taken while deleting:
$rm file1 - Removes file1
$rm -i file1- Removes file interactively. Removes after
confirmation
$rm -r dir1- Removes files from dir1 recursively
$rm -ir dir1- Removes file from dir1 recursively and
interactively
Commands
To rename file1 as file2 by:
$mv file1 file2
To rename directories by:
$mv old-dir new-dir
mv actually copies old-file to new-file and removes old-file
To copy file1 to file2 by:
$cp file1 file2
To copy files to directory
$cp file1 file2 dir-name
Can copy files across directories by providing absolute or relative
path:
$cp /usr1/file1 /usr2/file1
Commands
To change the mode of access on a file :
chmod u+x,g-x file1
chmod o-rwx file2
chmod 777 file3
To change the ownership of a file :
chown user2 file1
To change the group ownership of a file :
chgrp group2 file1
To change the group of a user :
usermod –g group2 user1
Try these Commands !!!
tar –cvf <filename>.tar <dirname>
tar –xvf <filename>.tar
tar –zxvf <compressed file>
gzip <filename>
gunzip <filename>.z
Try these Commands !!!
ps
tty
stty
date
whoami
who
bc – calculator
id
clear
echo $?
locate <filename>
Try these commands !!!
echo “ Today is date "
echo “ Today is `date` ”
echo $PWD
echo $PATH
echo $OSTYPE
echo $BASH
echo $BASH_VERSION
echo $PATH
echo $SHELL
echo $HOME
VI Editor
To insert new text esc + i
To append text esc + a
To insert text at line start esc + I
To append text line end esc + A
To save file esc + : + w
To save file with file name esc + : + w "filename“
To quit the vi editor esc + : + q
To quit without saving esc + : + q!
To save and quit vi editor esc + : + wq or x
To search for specified word
in forward direction esc + /word
VI Editor
To continue with search n
To search for specified word
in backward direction esc + ?word
To copy the line where
cursor is located esc + yy
To paste the text just deleted
or copied at the cursor esc + p
To delete entire line where
cursor is located esc + dd
To delete word from
cursor position esc + dw
VI Editor
To move up one line k
To move down one line j
To move left one character h
To move right one character l
To move one word right w
To move one word left b
To set numbers for lines esc + :set nu
To unset numbers for lines esc + :set nonu
THANKS