Unix Introduction and Basic Commands - V1.0
Unix Introduction and Basic Commands - V1.0
TCS- INTERNAL
Structure of a computer system
●
Hardware-CPU,Memory,I/O devices
●
Operating system-
●
Application programs-word
processors,browsers
●
Users-people,machines,other computers
Document Name
TCS Internal
Structure of a computer system
●
Hardware-CPU,Memory,I/O devices
●
Operating system-
●
Application programs-word
processors,browsers
●
Users-people,machines,other computers
Document Name
TCS Internal
Responsibilities of OS
●
Program execution
●
I/O operations
●
File system manipulation
●
Communication
●
Error detection
Document Name
TCS Internal
Types of OS
●
Single User Single Tasking OS- eg : MS-DOS
●
Single User Multitasking OS – eg: Windows
●
Multiprogramming OS- eg : Unix
Document Name
TCS Internal
Functions of OS
●
Process management
●
Memory management
●
Storage management
●
Device management
Document Name
TCS Internal
Unix-introduction
●
Unix was originally developed in 1969 by a group of AT&T employees Ken
Thompson, Dennis Ritchie, Douglas McIlroy, and Joe Ossanna at Bell Labs.
●
There are various Unix variants available in the market. Solaris Unix, AIX, HP
Unix and BSD are a few examples. Linux is also a flavor of Unix which is freely
available.
Document Name
TCS Internal
Unix Architecture
Document Name
TCS Internal
Unix Architecture
●
Kernel – it is a collection of programs written in C that runs directly on hardware.It
interacts with the hardware and most of the tasks like memory management, task
scheduling and file management.
●
Shell − The shell is the utility that processes your requests. When you type in a
command at your terminal, the shell interprets the command and calls the program
that you want.
Document Name
TCS Internal
Unix Architecture
●
Types of shell:
Bourne Shell: executable file name: sh
C shell: csh
Korn shell:ksh
Restricted shell: restricted version of Bourne shell
Document Name
TCS Internal
Unix File System
Document Name
TCS Internal
Unix Architecture
●
Types of shell:
Bourne Shell: executable file name: sh
C shell: csh
Korn shell:ksh
Restricted shell: restricted version of Bourne shell
Document Name
TCS Internal
How to work in Unix
Document Name
TCS Internal
Basicacommands
To create directory in Unix
To create a file
- Remove directory
Document Name
TCS Internal
Directory & File management
HolyAngelsSchool – Teachers, Students
/home/u390341/HolyAngelsSchool
Document Name
TCS Internal
Pipe
2) a=30
b=20
echo “$a + $b” | bc
Document Name
TCS Internal
Date/bc/cal
●
date- To get the date related information.
date -r newfile.txt
date -R
date -s
●
cal - To get the Calendar details
Document Name
TCS Internal
Filters
cat, cat >, cat>> – Viewing all records and editing files
Document Name
TCS Internal
Filters – wc/head/tail/
Document Name
TCS Internal
Filters – sort/uniq
Sort filename
Sort -r filename
Document Name
TCS Internal
Filters – cut/paste/join
Document Name
TCS Internal
Filters – grep
Document Name
TCS Internal
Filters – sed
Eg: sed -e '/Mumbai/g places.txt Space out the line with Mumbai
sed -n '/Mumbai/p places.txt print the line with Mumbai
sed -e d places.txt delete the entire lines
sed -e 3d places.txt delete the 3rd line
sed -e '/Mumbai/d' places.txt search and delete line
sed G places.txt To insert line
sed 's/Chennai/Trichy/g' places.txt Replace Chennai with
Trichy
Document Name
TCS Internal
Filters – awk
awk Blocks
BEGIN END
Document Name
TCS Internal
Filters – awk
●
awk '{print}' places.txt print the content of file
●
awk -F "," '{print$1, $3}' ManagerDetailsBkp Print some fields
●
awk '/Chennai/' places.txt search & print
●
awk '/Jackson/' ManagerDetailsBkp| awk -F "," '{print$1, $2}'
●
awk '/Clara/' ManagerDetailsBkp| awk -F ";" '{print$1, $3}'
Document Name
TCS Internal
Filters – Calculation & Conditions
BEGIN & END blocks are used to perform the calculation, conditions
and print result.
●
awk -F "," 'BEGIN {S=0}{S=S+$5} END {print "Total Salary per
month ", S}' EmployeeDetails.txt
●
awk '/10000/ {count++} END {print " Count of Employees with
salary 10K ", count}' EmployeeDetails.txt
●
awk -F "," '/10000/ {print " Name of Employees with salary 10K ",
$1}' EmployeeDetails.txt
●
awk 'BEGIN{FS=",";OFS="$"}{print $1,$2}' EmployeeDetails.txt
Document Name
TCS Internal
Filters – Calculation & Conditions
●
awk 'END{print FNR}' EmployeeDetails.txt print total
number of lines in a file
●
awk 'BEGIN{FS=","}{print length($1)}' EmployeeDetails.txt Uses
builtin string function to find out the length of field values
●
awk 'BEGIN{s=1;while (s<102) {print s;++s}}' print 1 to 101
●
awk 'BEGIN{FS=",";OFS="$"}{print $1,$2}' EmployeeDetails.txt
●
awk 'BEGIN{FS=OFS=","}{if($3=="Kolkota") {(gsub($5,"25000"))}}
1' EmployeeDetails.txt
●
tail -n5 input1|awk 'BEGIN{FS=","}{c=$1" "$2;print
"name&age:";print c;print "loc:";print $3}' EmployeeDetails.txt
Document Name
TCS Internal
Shell Scripting
Benefits:
●
Automation of repetitive task
●
Create own tools or utilities
●
Automation of command input
●
Create simple application
Document Name
TCS Internal
Shell Scripting
Example:
vi list.sh
#!/bin/sh
ls
vi print.sh
#!/bin/sh
echo “Hello World”
vi calc.sh
#!/bin/sh
a=200 b=100
Echo “$a+$b” | bc
Document Name
TCS Internal
Shell Scripting
vi listcity.sh
#!/bin/sh
grep Idukki empcity
vi calc.sh
#!/bin/sh
echo "Value 0f A = $1"
echo "Value of B = $2"
echo "$1 + $2" | bc
Document Name
TCS Internal
Shell Scripting – File conditions
-f & -e options can be used to make sure that the file used is a existing
and its a regular file
-f filename ==> To make sure that the file is a regular file
-e file name ==> To make sure that the file exists.
Sample code:
#!/bin/sh
if [ -e places.txt ] then echo "File exists"
else echo "File doesn't exist"
fi
if [ -f places.txt ] then echo "File is a regular file"
else echo "File is a Dictionary"
fi
cat places.txt
Document Name
TCS Internal
Shell Scripting
vi condition.sh
#!/bin/sh
a=355
b=353
if [ $a -eq $b ]
then
echo "a & b are equal"
else
echo "a & b are not equal"
fi
sh condition.sh
Document Name
TCS Internal
Thank You!!
TCS- INTERNAL