SlideShare a Scribd company logo
HSBC Global Technology   UNIX -Kirtikumar Shinde
Topics 1. Introduction Unix Filesystem File Permissions Advanced Commands Shell Shell Programming  AWK My Learnings Questions?
Introduction Multi-user  and Multitasking OS Mostly Written in C at Bell Labs Most of the servers are on Unix Unix Flavors Solaris HP AIX Linux Current DS Server – Which Unix?
Introduction Architecture
Unix File System An upside-down Tree / etc bin export home user ad s3910120 dev tmp exam.txt work hobby.c proj1 date cal . . . . . . . . . .  . . . . . . . . . . . . . . .
File permissions Changing permissions chmod g+w empl.txt chmod 754 empl.txt Changing ownership chown gcdv_dev empl.txt Changing group chgrp develp empl.txt reading others group owner 1 0 0 1 0 1 1 1 1 - r - r - x r x w execution writing
Advanced Commands Sort Sorts the contents of a file .  sort [-b f n r o t] [file name(s)]   Takes the contents of a file(s) and displays it in sorted order.  Flags: -b ignores blanks -f change all lower case letter to upper case before  comparing -n numeric sort -r reverse usual order -o sends output of command to some file -t field delimiter E.g.  To sort the Emp.txt on 2 nd  field in reverse order $sort -t, -n -r +2 Emp.txt
Advanced Commands grep Searches a file for pattern .   grep [-c i l v]  <pattern> [file name(s)]   Takes the contents of a file(s) and displays it in sorted order. Flags: -c displays count of matching lines. -i ignore the case while searching -l lists the names of files that matches pattern -v displays all lines that don’t contain the pattern  E.g.   To display all lines in the ‘Emp.txt’ that match either the abc or xyz string:   $grep &quot;abc|xyz&quot; Emp.txt
Advanced Commands tar Compression and decompression of files.   tar -(x|c) [ v f r]  <tarfile> [file name(s)]   Flags: -x extract from file. -c create new extract file. -v displays list files -f name of file follows -r append to old extract.  E.g .  To compress file Emp.txt   $tar -cvf Emp.tar Emp.txt To decompress file Emp.tar   $tar -xvf Emp.tar
Shell Command interpreter that waits for commands, executes them and displays the results Bourne shell Developed by Steve Bourne at AT&T Korn shell Developed by David Korn at AT&T C-shell Developed by Bill Joy for Berkeley Unix
Shell Shell works as follows: Shell displays a prompt.  You type in a command.  You press the return key.  The shell interprets the commands typed and tries to find the correct programs to run.  The kernel runs the requested programs and returns the results to the shell.  The shell displays the command prompt again
Shell Which Shell I am in ? finger –m  myusername Know your shell – Korn Shell – its features Aliases – It allows shorthand for commands. Command history – Lets you recall previously entered commands. Command line editing – Allows us to edit commands vi style. Integrated programming features – It enables common programming tasks to be done cleanly & without creating extra processes. Support regular expressions. Advanced I/O features – Ability to carry out two way communication with concurrent processes. Increased speed of shell code execution. Has highly robust security features.
Shell system variables PATH = Defines path shell must search in order to execute any command or file. HOME = Indicates default working directory of the user. PS1 = System prompt 1. PS2 = System prompt 2, default value is “>”. Shell
UNIX  S hell Programming Shell Script (Shell Procedure) A program written in shell programming language is known as a shell script or shell procedure. Shell Programming Language The shell programming language is a command language with a lot of features common to many computer programming languages, including the structured language constructs: sequence, selection, and iteration.  Command Languages Command languages are interpreted language s It allows then use of Unix commands in scripts
UNIX  S hell Programming Shell scripting keywords. Please Note : Script variables shouldn’t be same as keywords. Looping constructs, to be discussed in coming slides. set, unset Readonly Exit Ulimit Umask
UNIX  S hell Programming Create - Simple Hello World shell script. #!/bin/sh echo &quot;Hello World“ Make Files Executable $ chmod  777   HelloWorld.sh Execute the shell script Observe the output ‘Hello World’ will be between two command prompts. $  HelloWorld.sh
UNIX  S hell Programming Assignments Value assignments. String assignment –   var=“Your Name”  Think if not within double quotes. $echo $var think if not  $ Making variable readonly. a=50 readonly a
UNIX  S hell Programming echo and Escape Characters Display strings as “printf” in C The echo command recognizes escape characters. Escape characters all start with the backslash ( \ ), and you can use them as part of the echo command argument string.  E.g. $ echo  “\nHello\n”
UNIX  S hell Programming Passing parameters to a Shell script Consider Welcome.sh, & we are sending  name  as parameter to a Shell Script. Welcome.sh Vikram  think If you want to send First name & Last name as one parameter.  In above case 0 th  parameter value considered will be script name. 1 st  parameter value considered will be name, i.e.Vikram. Accessing parameters in a Shell script Parameter to a shell script starts from index 1. Its value is retrieved by using $1 & so on. … Think how you will access parameter beyond 9 th  parameter.
UNIX  S hell Programming Shell Positional Variable $0 : command itself $1  : first parameter $n  : nth parameter $# : no. of parameters $? : exit status of last command executed $* : all parameters $$ : process number of shell $! : PID of last background process
UNIX  S hell Programming if-then  and if-then-else The if-then Construct if [ condition ] then true-commands f i The if-then-else Construct if [ condition ] then true-commands else false-command(s) fi
UNIX  S hell Programming if-then-elif if [ condition1 ] then commands_1 elif  [ condition2 ] then commands_2 else commands_n fi
UNIX  S hell Programming test Command The test command is a built-in shell command that evaluates the expression given to it as an argument and return true if the expression is true, if otherwise, false. You can use square brackets ( [  ] ) instead of the word test. Example if test $str1 = $str2  then echo “Something” fi if [$str1 = $str2]  then echo “Something” fi
UNIX  S hell Programming Logical Operators -a  AND  Operator -o  OR  Operator !  NOT  Operator Numeric Test Operators -eq Is number1 equal to number2 ? -ne Is number 1  not equal to number2 ? -gt Is number1 great than  number2 ? -ge Is number1 great than or equal to number2 ? -lt Is number1 less than number2 ? -le Is number1 less than or equal to number2 ? E.g if test $var –lt 10 then echo “Something” fi
UNIX  S hell Programming String Test Operators string1 = string2 Does string1 match string2? string1 != string2 Does string1 not match string2? -n string Does string contain characters? -z string   Is string an empty string? E.g. if test $str1 = $str2  then echo “Something” fi Think if no space on both sides of an operator
UNIX  S hell Programming File Test Operators -s file True if File size is greater than 0 -f file True if File exists & not a directory -d file True if file exists & is a directory file.  -r file  True if file exists & you have read permission on it. -w file  True if file exists & you have write permission on it. -x file True if file exists & you have execute permission on it. E.g if [ –f $filename ] then echo “Something” fi Think if no space on both sides of an option.
UNIX  S hell Programming The expr Command Arithmetic Operators + : Addition operator - : Subtraction operator / : Division operator * : Multiplication operator % : Remainder operator Expressions Arithmetic expression a=`expr $a + $b`  … think if no space both the sides of + & space both the sides of =. Floating point arithmetic expression   a=`expr $a + $b | bc ` String expression path=$path1”/”$path2
UNIX  S hell Programming While Loop while [ condition ] do command(s) done For Loop for variable in list-of-value do command(s) done
AWK Introduction to awk. awk is a programming language designed to search for, match patterns, and perform actions on files. awk programs are generally quite small, and are interpreted.  awk scans input lines one after the other, searching each line to see if it matches a set of patterns or conditions specified in the awk program. For each pattern, an action is specified. The action is performed when the pattern matches that of the input line. Sample awk command: awk ‘/pattern/’’{print $0}’ file1
My Learnings When I will go for Shell scripting. Automating my regular tasks. Customizing my work environment. Task is pretty simple When I will avoid Shell scripting . It needs interaction with multiple applications. Problem is relatively complex involves more than one tool. Lookups or finding data .
Questions ?
Thank You

More Related Content

PPT
Using Unix
PPT
Airlover 20030324 1
PPS
UNIX - Class1 - Basic Shell
PPT
Talk Unix Shell Script 1
PPT
Unix Basics
PPT
Talk Unix Shell Script
PPT
Unix And C
PPT
Bioinformatica 29-09-2011-p1-introduction
Using Unix
Airlover 20030324 1
UNIX - Class1 - Basic Shell
Talk Unix Shell Script 1
Unix Basics
Talk Unix Shell Script
Unix And C
Bioinformatica 29-09-2011-p1-introduction

What's hot (20)

PPTX
More on Lex
PDF
Unix Commands
DOC
PDF
IO Streams, Files and Directories
PPT
Learning sed and awk
PPTX
Pipes and filters
PDF
Unix Tutorial
ODP
PDF
Writing Parsers and Compilers with PLY
PDF
Linux intro 5 extra: awk
PPTX
Unix shell scripting basics
PPT
Learn Ruby Programming in Amc Square Learning
PPT
Perl Basics with Examples
PPT
Ruby programming introduction
DOCX
Awk programming
PPT
Programming in Computational Biology
PPTX
Shell scripting
More on Lex
Unix Commands
IO Streams, Files and Directories
Learning sed and awk
Pipes and filters
Unix Tutorial
Writing Parsers and Compilers with PLY
Linux intro 5 extra: awk
Unix shell scripting basics
Learn Ruby Programming in Amc Square Learning
Perl Basics with Examples
Ruby programming introduction
Awk programming
Programming in Computational Biology
Shell scripting
Ad

Viewers also liked (20)

PDF
Awk Unix Utility Explained
PPT
Testingtechniques And Strategy
ODP
What Linux is what you should also have on your computer.
PPT
Unix day3 v1.3
KEY
Advanced Shell Scripting
PPT
Unix day2 v1.3
PPT
Unix day4 v1.3
ODP
Linux 101 Exploring Linux OS
PPTX
Presentation of awk
PPSX
Awk essentials
PPT
unix crontab basics
PPS
UNIX - Class6 - sed - Detail
PDF
Sed Unix Utility Explained
PDF
Shell script-sec
PPT
Chap06
PDF
Linux fundamental - Chap 15 Job Scheduling
PPT
Regular Expressions grep and egrep
PDF
Oracle 12c Multi Process Multi Threaded
KEY
Czzawk
PPTX
Practical unix utilities for text processing
Awk Unix Utility Explained
Testingtechniques And Strategy
What Linux is what you should also have on your computer.
Unix day3 v1.3
Advanced Shell Scripting
Unix day2 v1.3
Unix day4 v1.3
Linux 101 Exploring Linux OS
Presentation of awk
Awk essentials
unix crontab basics
UNIX - Class6 - sed - Detail
Sed Unix Utility Explained
Shell script-sec
Chap06
Linux fundamental - Chap 15 Job Scheduling
Regular Expressions grep and egrep
Oracle 12c Multi Process Multi Threaded
Czzawk
Practical unix utilities for text processing
Ad

Similar to Unix (20)

PPT
Shell programming
PPT
Unix And Shell Scripting
PPT
Shell Scripting
PPTX
Bash Shell Scripting
PPTX
Basics of shell programming
PPTX
Basics of shell programming
PPT
Introduction to shell scripting ____.ppt
PPTX
SHELL PROGRAMMING
PPT
34-shell-programming.ppt
PPT
34-shell-programming asda asda asd asd.ppt
PPT
Shell Scripts
PPTX
OS-Module 2 Linux Programming Important topics
PPTX
shellScriptAlt.pptx
ODP
Shellscripting
PDF
Scripting and the shell in LINUX
PPT
Advanced linux chapter ix-shell script
PDF
Linux Command Line - By Ranjan Raja
PPT
Spsl by sasidhar 3 unit
PPTX
Wildcards, Simple Shell Programs and Shell Variables
PDF
Shell programming
Unix And Shell Scripting
Shell Scripting
Bash Shell Scripting
Basics of shell programming
Basics of shell programming
Introduction to shell scripting ____.ppt
SHELL PROGRAMMING
34-shell-programming.ppt
34-shell-programming asda asda asd asd.ppt
Shell Scripts
OS-Module 2 Linux Programming Important topics
shellScriptAlt.pptx
Shellscripting
Scripting and the shell in LINUX
Advanced linux chapter ix-shell script
Linux Command Line - By Ranjan Raja
Spsl by sasidhar 3 unit
Wildcards, Simple Shell Programs and Shell Variables

More from nazeer pasha (20)

PPT
PPT
Tomcat Configuration (1)
PPT
Test Techniques
PPT
Testing Types Presentation
PDF
Good Ppt On Risk
PDF
Bug Advocacy
PDF
Doe Taguchi Basic Manual1
PDF
Teaching Testing Qw%202001
PDF
Orth Arrays
PPT
Testing
PDF
Tc Checklist
PDF
Software Testing Guide
PDF
Cstp Certification Compare
PPT
Blackboxtesting 02 An Example Test Series
PDF
Exploratory Testing
PDF
Chanakya Niti
PPT
Unit Testing
PPT
Testing
PPT
Testing Types And Models
PDF
Swtesting
Tomcat Configuration (1)
Test Techniques
Testing Types Presentation
Good Ppt On Risk
Bug Advocacy
Doe Taguchi Basic Manual1
Teaching Testing Qw%202001
Orth Arrays
Testing
Tc Checklist
Software Testing Guide
Cstp Certification Compare
Blackboxtesting 02 An Example Test Series
Exploratory Testing
Chanakya Niti
Unit Testing
Testing
Testing Types And Models
Swtesting

Recently uploaded (20)

PDF
Unkipdf.pdf of work in the economy we are
PDF
USS pension Report and Accounts 2025.pdf
PPTX
IGCSE ECONOMICS 0455 Foreign Exchange Rate
PPTX
kyc aml guideline a detailed pt onthat.pptx
PPT
features and equilibrium under MONOPOLY 17.11.20.ppt
PDF
Statistics for Management and Economics Keller 10th Edition by Gerald Keller ...
PPTX
Grp C.ppt presentation.pptx for Economics
PDF
Dialnet-DynamicHedgingOfPricesOfNaturalGasInMexico-8788871.pdf
PDF
Bitcoin Layer August 2025: Power Laws of Bitcoin: The Core and Bubbles
PPTX
FL INTRODUCTION TO AGRIBUSINESS CHAPTER 1
PPT
KPMG FA Benefits Report_FINAL_Jan 27_2010.ppt
PDF
Buy Verified Stripe Accounts for Sale - Secure and.pdf
PPTX
Introduction to Customs (June 2025) v1.pptx
PPTX
OAT_ORI_Fed Independence_August 2025.pptx
PDF
3CMT J.AFABLE Flexible-Learning ENTREPRENEURIAL MANAGEMENT.pdf
PDF
7a Lifetime Expected Income Breakeven Comparison between SPIAs and Managed Po...
PDF
CLIMATE CHANGE AS A THREAT MULTIPLIER: ASSESSING ITS IMPACT ON RESOURCE SCARC...
PPTX
Basic Concepts of Economics.pvhjkl;vbjkl;ptx
PPTX
PPT-Lesson-2-Recognize-a-Potential-Market-2-3.pptx
Unkipdf.pdf of work in the economy we are
USS pension Report and Accounts 2025.pdf
IGCSE ECONOMICS 0455 Foreign Exchange Rate
kyc aml guideline a detailed pt onthat.pptx
features and equilibrium under MONOPOLY 17.11.20.ppt
Statistics for Management and Economics Keller 10th Edition by Gerald Keller ...
Grp C.ppt presentation.pptx for Economics
Dialnet-DynamicHedgingOfPricesOfNaturalGasInMexico-8788871.pdf
Bitcoin Layer August 2025: Power Laws of Bitcoin: The Core and Bubbles
FL INTRODUCTION TO AGRIBUSINESS CHAPTER 1
KPMG FA Benefits Report_FINAL_Jan 27_2010.ppt
Buy Verified Stripe Accounts for Sale - Secure and.pdf
Introduction to Customs (June 2025) v1.pptx
OAT_ORI_Fed Independence_August 2025.pptx
3CMT J.AFABLE Flexible-Learning ENTREPRENEURIAL MANAGEMENT.pdf
7a Lifetime Expected Income Breakeven Comparison between SPIAs and Managed Po...
CLIMATE CHANGE AS A THREAT MULTIPLIER: ASSESSING ITS IMPACT ON RESOURCE SCARC...
Basic Concepts of Economics.pvhjkl;vbjkl;ptx
PPT-Lesson-2-Recognize-a-Potential-Market-2-3.pptx

Unix

  • 1. HSBC Global Technology UNIX -Kirtikumar Shinde
  • 2. Topics 1. Introduction Unix Filesystem File Permissions Advanced Commands Shell Shell Programming AWK My Learnings Questions?
  • 3. Introduction Multi-user and Multitasking OS Mostly Written in C at Bell Labs Most of the servers are on Unix Unix Flavors Solaris HP AIX Linux Current DS Server – Which Unix?
  • 5. Unix File System An upside-down Tree / etc bin export home user ad s3910120 dev tmp exam.txt work hobby.c proj1 date cal . . . . . . . . . . . . . . . . . . . . . . . . .
  • 6. File permissions Changing permissions chmod g+w empl.txt chmod 754 empl.txt Changing ownership chown gcdv_dev empl.txt Changing group chgrp develp empl.txt reading others group owner 1 0 0 1 0 1 1 1 1 - r - r - x r x w execution writing
  • 7. Advanced Commands Sort Sorts the contents of a file . sort [-b f n r o t] [file name(s)] Takes the contents of a file(s) and displays it in sorted order. Flags: -b ignores blanks -f change all lower case letter to upper case before comparing -n numeric sort -r reverse usual order -o sends output of command to some file -t field delimiter E.g. To sort the Emp.txt on 2 nd field in reverse order $sort -t, -n -r +2 Emp.txt
  • 8. Advanced Commands grep Searches a file for pattern . grep [-c i l v] <pattern> [file name(s)] Takes the contents of a file(s) and displays it in sorted order. Flags: -c displays count of matching lines. -i ignore the case while searching -l lists the names of files that matches pattern -v displays all lines that don’t contain the pattern E.g. To display all lines in the ‘Emp.txt’ that match either the abc or xyz string: $grep &quot;abc|xyz&quot; Emp.txt
  • 9. Advanced Commands tar Compression and decompression of files. tar -(x|c) [ v f r] <tarfile> [file name(s)] Flags: -x extract from file. -c create new extract file. -v displays list files -f name of file follows -r append to old extract. E.g . To compress file Emp.txt $tar -cvf Emp.tar Emp.txt To decompress file Emp.tar $tar -xvf Emp.tar
  • 10. Shell Command interpreter that waits for commands, executes them and displays the results Bourne shell Developed by Steve Bourne at AT&T Korn shell Developed by David Korn at AT&T C-shell Developed by Bill Joy for Berkeley Unix
  • 11. Shell Shell works as follows: Shell displays a prompt. You type in a command. You press the return key. The shell interprets the commands typed and tries to find the correct programs to run. The kernel runs the requested programs and returns the results to the shell. The shell displays the command prompt again
  • 12. Shell Which Shell I am in ? finger –m myusername Know your shell – Korn Shell – its features Aliases – It allows shorthand for commands. Command history – Lets you recall previously entered commands. Command line editing – Allows us to edit commands vi style. Integrated programming features – It enables common programming tasks to be done cleanly & without creating extra processes. Support regular expressions. Advanced I/O features – Ability to carry out two way communication with concurrent processes. Increased speed of shell code execution. Has highly robust security features.
  • 13. Shell system variables PATH = Defines path shell must search in order to execute any command or file. HOME = Indicates default working directory of the user. PS1 = System prompt 1. PS2 = System prompt 2, default value is “>”. Shell
  • 14. UNIX S hell Programming Shell Script (Shell Procedure) A program written in shell programming language is known as a shell script or shell procedure. Shell Programming Language The shell programming language is a command language with a lot of features common to many computer programming languages, including the structured language constructs: sequence, selection, and iteration. Command Languages Command languages are interpreted language s It allows then use of Unix commands in scripts
  • 15. UNIX S hell Programming Shell scripting keywords. Please Note : Script variables shouldn’t be same as keywords. Looping constructs, to be discussed in coming slides. set, unset Readonly Exit Ulimit Umask
  • 16. UNIX S hell Programming Create - Simple Hello World shell script. #!/bin/sh echo &quot;Hello World“ Make Files Executable $ chmod 777 HelloWorld.sh Execute the shell script Observe the output ‘Hello World’ will be between two command prompts. $ HelloWorld.sh
  • 17. UNIX S hell Programming Assignments Value assignments. String assignment – var=“Your Name” Think if not within double quotes. $echo $var think if not $ Making variable readonly. a=50 readonly a
  • 18. UNIX S hell Programming echo and Escape Characters Display strings as “printf” in C The echo command recognizes escape characters. Escape characters all start with the backslash ( \ ), and you can use them as part of the echo command argument string. E.g. $ echo “\nHello\n”
  • 19. UNIX S hell Programming Passing parameters to a Shell script Consider Welcome.sh, & we are sending name as parameter to a Shell Script. Welcome.sh Vikram think If you want to send First name & Last name as one parameter. In above case 0 th parameter value considered will be script name. 1 st parameter value considered will be name, i.e.Vikram. Accessing parameters in a Shell script Parameter to a shell script starts from index 1. Its value is retrieved by using $1 & so on. … Think how you will access parameter beyond 9 th parameter.
  • 20. UNIX S hell Programming Shell Positional Variable $0 : command itself $1 : first parameter $n : nth parameter $# : no. of parameters $? : exit status of last command executed $* : all parameters $$ : process number of shell $! : PID of last background process
  • 21. UNIX S hell Programming if-then and if-then-else The if-then Construct if [ condition ] then true-commands f i The if-then-else Construct if [ condition ] then true-commands else false-command(s) fi
  • 22. UNIX S hell Programming if-then-elif if [ condition1 ] then commands_1 elif [ condition2 ] then commands_2 else commands_n fi
  • 23. UNIX S hell Programming test Command The test command is a built-in shell command that evaluates the expression given to it as an argument and return true if the expression is true, if otherwise, false. You can use square brackets ( [ ] ) instead of the word test. Example if test $str1 = $str2 then echo “Something” fi if [$str1 = $str2] then echo “Something” fi
  • 24. UNIX S hell Programming Logical Operators -a AND Operator -o OR Operator ! NOT Operator Numeric Test Operators -eq Is number1 equal to number2 ? -ne Is number 1 not equal to number2 ? -gt Is number1 great than number2 ? -ge Is number1 great than or equal to number2 ? -lt Is number1 less than number2 ? -le Is number1 less than or equal to number2 ? E.g if test $var –lt 10 then echo “Something” fi
  • 25. UNIX S hell Programming String Test Operators string1 = string2 Does string1 match string2? string1 != string2 Does string1 not match string2? -n string Does string contain characters? -z string Is string an empty string? E.g. if test $str1 = $str2 then echo “Something” fi Think if no space on both sides of an operator
  • 26. UNIX S hell Programming File Test Operators -s file True if File size is greater than 0 -f file True if File exists & not a directory -d file True if file exists & is a directory file. -r file True if file exists & you have read permission on it. -w file True if file exists & you have write permission on it. -x file True if file exists & you have execute permission on it. E.g if [ –f $filename ] then echo “Something” fi Think if no space on both sides of an option.
  • 27. UNIX S hell Programming The expr Command Arithmetic Operators + : Addition operator - : Subtraction operator / : Division operator * : Multiplication operator % : Remainder operator Expressions Arithmetic expression a=`expr $a + $b` … think if no space both the sides of + & space both the sides of =. Floating point arithmetic expression a=`expr $a + $b | bc ` String expression path=$path1”/”$path2
  • 28. UNIX S hell Programming While Loop while [ condition ] do command(s) done For Loop for variable in list-of-value do command(s) done
  • 29. AWK Introduction to awk. awk is a programming language designed to search for, match patterns, and perform actions on files. awk programs are generally quite small, and are interpreted. awk scans input lines one after the other, searching each line to see if it matches a set of patterns or conditions specified in the awk program. For each pattern, an action is specified. The action is performed when the pattern matches that of the input line. Sample awk command: awk ‘/pattern/’’{print $0}’ file1
  • 30. My Learnings When I will go for Shell scripting. Automating my regular tasks. Customizing my work environment. Task is pretty simple When I will avoid Shell scripting . It needs interaction with multiple applications. Problem is relatively complex involves more than one tool. Lookups or finding data .