8/3/2019 UNIX Training Basics
1/37
Click to add text
Fundamentals of UNIX
8/3/2019 UNIX Training Basics
2/37
Agenda
UNIX Basics Definition , History, ArchitectureVarious flavors, Design Principles
UNIX System Processes
File System
Types of Files
Types of ShellsBasic UNIX Commands
8/3/2019 UNIX Training Basics
3/37
What is UNIX ?
Multi User, Multi Tasking, Multi Processing, TimeSharing, Portable, Networking, Strong Security (Secure)Operating System
Powerful Operating System
Written in High Level Language
Hierarchical Directory Structure
Supports internet
8/3/2019 UNIX Training Basics
4/37
How the Name UNIX appeared ?
MULTICS(MULTiplexed Information & Computing Service)1965
Bell Labs + GE + MIT
UNICS( UNiplexed Information & Computing Service )1969
Bell Labs
Ken Thompson along with Dennis Ritchie
UNIX
Bell Labs Brian Kernighan
1969
8/3/2019 UNIX Training Basics
5/37
History of UNIX
1969, First developed
Ken Thompson & Dennis Ritchie,
Research Group at Bell Laboratories
Version 1, 2 - Assembly Language.Version 3 - C Language, Bell Labs
8/3/2019 UNIX Training Basics
6/37
History of UNIX Versions
8/3/2019 UNIX Training Basics
7/37
UNIX Flavors
Sun Solaris 10
HP-UX 11i v3
Santa Cruz Operation (SCO)
LINUX
AIX (Advanced Interactive eXecutive)(IBM)
MINIX
XENIX
8/3/2019 UNIX Training Basics
8/37
Hardware
System Call Interface
General UNIX Architecture
UNIX Commands
& Libraries
User Applications
Kernel
HardwareDATABASE Compilers
SHELLs
ksh, sh, csh etc.
8/3/2019 UNIX Training Basics
9/37
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 withHardware.
8/3/2019 UNIX Training Basics
10/37
Unix Design PrinciplesEverything 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
8/3/2019 UNIX Training Basics
11/37
What is a Process ?
Fundamental to almost all operatingsystems = program in execution
Has usually separate address space
It is an instance of a running program.
8/3/2019 UNIX Training Basics
12/37
Processes in Windows
Windows Task Managerin
Windows NT /
Windows XP/Windows 2000 /
8/3/2019 UNIX Training Basics
13/37
Process CreationProcesses are created during:
system initialization (Init, Swapper etc.)
by another process
user request (from shell)
Batch job (timed, Unixat
orcron
)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.
8/3/2019 UNIX Training Basics
14/37
UNIX Processes/home/ginger>ps -ef|more
UID PID PPID C STIME TTY TIME CMD
root 0 0 0 08:09:31 ? 0:38 sched
root 1 0 0 08:09:31 ? 0:02 /etc/init -
root 2 0 0 08:09:31 ? 0:00 pageout
root 3 0 2 08:09:31 ? 08:49 fsflush
root 2262 1 0 08:13:53 ? 0:00 /usr/lib/saf/sac -t 300
root 988 986 0 08:11:31 ? 0:00 htt_server -port 9010 -syslog -message_locale C
root 1078 1 0 08:11:35 ? 0:00 ./ns-admin -d /apps/suitespot/3.62/admin-serv/config
root 11 1 0 08:09:35 ? 0:00 /platform/SUNW,Sun-Fire-15000/lib/cvcd
root 22 1 0 08:09:36 ? 0:06 vxconfigd -m boot
root 825 1 0 08:10:41 ? 0:00 /usr/platform/SUNW,Sun-Fire-15000/lib/sckmd
root 1196 1 0 08:11:36 ? 0:01 /usr/sbin/auditd
root 76 1 0 08:10:02 ? 0:00 /usr/lib/sysevent/syseventd
root 598 1 0 08:10:29 ? 0:01 /usr/lib/picl/picld
root 879 876 0 08:10:48 ? 2:40 /usr/lib/autofs/automountd
Each process is identified by a numbercalled Process Identifier (PID)PPID stands for Parent of the Process
8/3/2019 UNIX Training Basics
15/37
UNIX File Hierarchy
/(Root)
binsbin dev etc lib stand tmp usr
8/3/2019 UNIX Training Basics
16/37
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 apistmp all temp files
usr all user related files
8/3/2019 UNIX Training Basics
17/37
Types of filesOrdinary file (data file, text file etc.)
Directory (also treated as file)
Device fileLink File
Sticky bit file
8/3/2019 UNIX Training Basics
18/37
ShellWhat is a Shell ?
An Interface between User & Kernel
An environment for aScript/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
User
Shell
UNIX O.S.(Kernel)
Hardware
8/3/2019 UNIX Training Basics
19/37
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
e.g. LOGNAME, PATH, SHELL, PS1, HOME, PWD etc.
USERDEFINED Variables
i=10
v_string=jpmorganchase
ONLY String text needs to be enclosed
8/3/2019 UNIX Training Basics
20/37
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/sh2. K Shell to C Shell
$/bin/csh
8/3/2019 UNIX Training Basics
21/37
What is a UNIX Command ?
Binary file that resides in /usr/bin, /usr/local/bin or /bindirectory
What happens when executed ?
When executed by user/through program, sends the userrequest to KERNEL that understands what request is made andprovides services to the User command.
8/3/2019 UNIX Training Basics
22/37
UNIX Commands
Connect to a UNIX Machine
$telnet
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
8/3/2019 UNIX Training Basics
23/37
UNIX Commands
HOME Directory:
This is the directory along with its path that appears wheneverwe 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 thecommand pwd
This Directory Path is stored in SYSTEM Variable HOME.
List all files and subdirectories in Ascending order of file creationie., latest file created present at the last line
$ls lrt
8/3/2019 UNIX Training Basics
24/37
By default a File has a Read and Write permission but no executepermission unlike a Directory.
8/3/2019 UNIX Training Basics
25/37
8/3/2019 UNIX Training Basics
26/37
UNIX CommandsTo see the help / manual of a UNIX Command
man $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 eg. cd dir1
To create a new empty file - $touch
To Create a new file or a shell script, use VI editor
8/3/2019 UNIX Training Basics
27/37
UNIX CommandsDisplay the contents of a file at Command Prompt.
cat
$cat test.txt
To find the no. of lines, chars, words in a file
wc
$wc test.txt
To change the Name of an existing file
$mv file1 file1.sh
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
8/3/2019 UNIX Training Basics
28/37
UNIX CommandsTo 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
8/3/2019 UNIX Training Basics
29/37
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
8/3/2019 UNIX Training Basics
30/37
8/3/2019 UNIX Training Basics
31/37
UNIX Commands
To Check whether an Application/Script process is Running
$ps ef|grep
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
2. Kill the Process by using its Process ID obtained from above.
$kill -9
8/3/2019 UNIX Training Basics
32/37
UNIX Commands
To have a tree view of the processes running for an Script/jobthat is run.
1. Obtain the Process ID of the process
$ps ef|grep
2. Use ptree command for the Process ID obtained from above.
$ptree
To Search for a pattern (a word) in a file and display the record.
grep
$grep error 20061118.log
Here we are searching for the occurrence of error by usingkeyword error in the log file.
8/3/2019 UNIX Training Basics
33/37
UNIX Commands
Search irrespective of CASE sensitivity (UPPER/LOWER case) of thepattern to be searched.
$grep i error 20061118.log
In the Current Directory, to search for a pattern when file name isnot known
$grep il error *.log
To search for errors and warning appearing in a Log file
$egrep i error|warn 20061118.log
8/3/2019 UNIX Training Basics
34/37
UNIX Commands
To display list of ONLY directories
$ls lrt|grep d
To view a Growing Log file
$tail f
8/3/2019 UNIX Training Basics
35/37
Summary
8/3/2019 UNIX Training Basics
36/37
Common Discussions /Questions
?
8/3/2019 UNIX Training Basics
37/37
Thank U
Top Related