Exam Revision. Exam Details Time 90 minutes (1hour 30 minutes). Six questions! How long per question? Five parts per question. How long for each part?

Slides:



Advertisements
Similar presentations
UNIX Chapter 12 Redirection and Piping Mr. Mohammad Smirat.
Advertisements

Lecture 4 Shell environment III: - command alias & history; - job control; - editor (vim) CSE4251 The Unix Programming Environment 1.
CIS 118 – Intro to UNIX Shells 1. 2 What is a shell? Bourne shell – Developed by Steve Bourne at AT&T Korn shell – Developed by David Korn at AT&T C-shell.
A Practical Guide to Fedora and Red Hat Enterprise Linux Unit 4: More Command Line Interface (CLI) Chapter 7: The Linux Shell By Fred R. McClurg Linux.
LINUX System : Lecture 3 (English-Only Lecture) Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University Acknowledgement.
1 © 2001 John Urrutia. All rights reserved. Chapter 5 The Shell Overview.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
CS 497C – Introduction to UNIX Lecture 22: - The Shell Chin-Chih Chang
Linux+ Guide to Linux Certification, Second Edition
Now, return to the Unix Unix shells: Subshells--- Variable---1. Local 2. Environmental.
More Shell Basics CS465 - Unix. Unix shells User’s default shell - specified in /etc/passwd file To show which shell you are currently using: $ echo $SHELL.
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Introduction to Unix – CS 21 Lecture 5. Lecture Overview Lab Review Useful commands that will illustrate today’s lecture Streams of input and output File.
1 UNIX essentials (hands-on) the directory tree running programs the shell (using the T-shell) → command line processing → special characters → command.
Lecture 3  Shell Variables  Shell Command History  Job / Process Control  Directory Control.
5 UNIX Processes. Introduction  Processes  How to list them  How to terminate them  Process priorities  Scheduling jobs  Signals.
1 The Shell and some useful administrative Unix Commands How Unix works along with some additional, useful administrative Unix commands you might need.
2 Manual & Filestore. Introduction Using the manual The UNIX filestore File permissions.
3 File Processing Mauro Jaskelioff. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash.
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
Introduction to Shell Script Programming
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
BIF703 stdin, stdout, stderr Redirection. stdin, stdout, stderr Recall the Unix philosophy “do one thing well”. Unix has over one thousand commands (utilities)
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Title Slide CSS 404/504 The UNIX Operating System (2) By Ralph B. Bisland, Jr.
CS 2061 Shells Also known as: Unix Command Interpreter.
Command Line Variations Selected Readings in Chapters 3, 5, 6 u Project 1 kickoff u Streams & Redirection: Sections 5.2, 5.3 u Pipes and Tees: Sections.
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
Linux+ Guide to Linux Certification, Third Edition
1 UNIX essentials (hands-on) the directory tree running programs the shell → command line processing → special characters → command types → shell variables.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
Linux+ Guide to Linux Certification, Third Edition
Scripting Languages Course 2 Diana Trandab ă ț Master in Computational Linguistics - 1 st year
Linux+ Guide to Linux Certification Chapter Eight Working with the BASH Shell.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
1 Unix Seminar #1 T.J. Borrelli Lecturer for CS and NSSA February 6th, 2009.
I/O Redirection & Regular Expressions CS 2204 Class meeting 4 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Chapter Six Introduction to Shell Script Programming.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
CSCI 330 UNIX and Network Programming Unit IV Shell, Part 2.
Chapter 5: The Shell The Man in the Middle. In this chapter … The command line Input, output, and redirection Process management Wildcards and expansion.
Revision: Absolute and relative paths. (root) staffusrbinstudetc ResearchTeachingPrivate pgugitmasters xxxgtrxxx CUA Coursework1.txt CUA xxx02uxxx04u.
2 Manual & Filestore Mauro Jaskelioff. Introduction Using the manual The UNIX filestore File permissions.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
Linux+ Guide to Linux Certification, Second Edition
Introduction to Bash Shell. What is Shell? The shell is a command interpreter. It is the layer between the operating system kernel and the user.
Agenda The Linux File System (chapter 4 in text) Setting Access Permissions Directory vs File Permissions chmod Utility Symbolic Method Absolute Method.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Linux Administration Working with the BASH Shell.
Awk 2 – more awk. AWK INVOCATION AND OPERATION the "-F" option allows changing Awk's "field separator" character. Awk regards each line of input data.
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
The UNIX Shell Learning Objectives:
Lecture 2 Working with Files and Directories
The Linux Operating System
CSE 303 Concepts and Tools for Software Development
Basic UNIX OLC Training.
Introduction Paul Flynn
Shell Programming.
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
LPI Linux Certification
Presentation transcript:

Exam Revision

Exam Details Time 90 minutes (1hour 30 minutes). Six questions! How long per question? Five parts per question. How long for each part? You can take the unix sheet into the exam. You can READ the exam paper at the start (before the exam starts – so get there early).

No questions on History Basics of commands, redirection, permissions, processes. awk, egrep and regular expressions. Lots of general questions.

pathnames Special symbols can be used in pathnames..the directory one level above this../.. the directory two levels above this. the current directory ~this user’s home directory ~usera specific user’s home directory *wildcard matching any string ?wildcard matching any single character

Relative and Absolute Pathnames Revisited (root) staffusrbinstudetc ResearchTeachingPrivate pgugitmasters xxxgtrxxx CUA Coursework1.txt CUA xxx02uxxx04u MVR Lecture1.ppt Lecture2.doc.profile /../../../stud You are here! /stud/ug/xxx04u.. /stud/ug../..../../../.. ~~xxx04u RelativeAbsolute./stud/ug/xxx04u/CUA

Permissions lists Specify who can do what There are three kinds of who: uthe user (owner) gmembers of the user’s group oothers - anyone else There are three kinds of what: rread wwrite xexecute

Setting and changing permissions -chmod chmod mode pathname is used to alter permissions lists Mode specifies a sequence of changes, each of the form who operation permission – who is u, g or o – operation is + (grant) or - (revoke) – permission is r, w or x Examples: chmod o-r g-r plan.doc chmod u+rwx Admin

The mode can also be a three digit octal number that is interpreted as a sequence of nine bits to set the whole permissions list at once: – chmod 644 progress.txt 644 is which is interpreted as rw- r-- r-- – chmod 777 progress.txt 777 is which is interpreted rwx rwx rwx – chmod 400 progress.txt 400 is which is interpreted as r Setting and changing permissions – chmod (2)

Setting and changing permissions – chmod (3) Files are created with a default permission – usually -rw- r-- r-- – depends upon the command used to create the file – set using the umask command

Finding Files find searches in a directory hierarchy find -name -print $ find /usr/share/doc/ -name 'post*' -print /usr/share/doc/postgresql /usr/share/doc/postgresql /html/postmaster-shutdown.html /usr/share/doc/postgresql /html/postmaster-start.html $ $ find. -name '*.txt' –print (recently can do without print)

Regular Expressions grep “That” poem will only find the string “That” in poem if it has an upper case ‘T’ followed by lower case ‘hat’ Regular expressions are much more powerful notation for matching many different text fragments with a single expression – i.e. could wish to find “That”, “that”, “tHaT”, etc.

Regular Expressions (2) Search expressions can be very complex and several characters have special meanings – to insist that That matches only at the start of the line use grep “^That” poem – to insist that it matches only at the end use grep “That$” poem – a dot matches any single character so that grep “c.t” poem matches cat, cbt, cct, etc.

Square brackets allow alternatives: – grep “[Tt]hat$” poem An asterisk allows zero or more repetitions of the preceding match – grep “^-*$” poem for lines with only -’s or empty – grep “^--*$” poem for lines with only -’s and at least one - – grep “Bengal.*Sumatra” poem for lines with Bengal followed sometime later by Sumatra Many flags to: – display only number of matching lines, ignore case, precede each line by its number on the file and so forth Regular Expressions (3)

STDOUT Stands for standard output This is where programs (usually) write any output they generate. By default STDOUT appears in your terminal window If you want to save the output to a file instead, use > – The file will be created – If the file already exists then it will be overwritten You can also use >> which appends the output onto a file’s contents

STDERR Stderr stands for standard error This is where programs usually write error messages. So even if you are redirecting the normal output to a file, you can still see error messages on the screen You can redirect STDERR using 2>

Aliases (bash) To define shorthand for complex commands alias name definition defines an alias alias hist=history alias ls='ls -F' alias alone shows you current aliases unalias name removes an alias unalias –a removes an alias

Killing Processes Use top Alternatively, use kill – kill E.g. kill – “-15” is the signal number – here, it means “stop the process cleanly” (i.e. close any files it is using) More about signals later… – “-9” means “kill the process whatever” Useful if all else fails! killall will send the signal to every process with that name.

Job Control (2) jobs allows you to: – Bring a job to the foreground fg % – Run a job in the background bg % – Suspend a job stop % – Terminate a job kill %

Control Key Sequences for Processes Some control sequences affect processes: – Ctrl-C - kill a process – Ctrl-D - exit a shell (send EOF) – Ctrl-S - suspend or pause the display of output – Ctrl-Q - resume or continue output from Ctrl-S

PATH To add the location of your scripts dir to your path echo $PATH export PATH="$PATH:~/scripts“ echo $PATH

execution permissions chmod u+x myScript.sh to give execution permissions to user. sh -x myScript.sh; shows which command is executed. you can enclose parts of script with

Using awk I could then invoke Awk to list all the gold pieces as follows: awk '/gold/' coins.txt This example demonstrates the simplest general form of an Awk program: awk { }

NR (number of records) The next example prints out how many coins are in the collection: awk 'END {print NR,"coins"}' coins.txt This yields: 13 coins

general form of an Awk program the general form of an Awk program to: awk 'BEGIN { } { } { }... END { }'

awk '/gold/ {ounces += $2} END {print "value = $" 425*ounces}' coins.txt This yields: (note ounces is user defined) value = $ Instead of doing it all from the command line We can do it all from a file, With the following syntax awk -f

AWK PROGRAM EXAMPLE Instead of doing it all from the command line We can do it all from a file, With the following syntax awk -f

SEARCH PATTERNS (1) /The/ /^The/ /The$/ /\$/ /[Tt]he/ /[a-z]/ /[a-zA-Z0-9]/

For example: /^[^a-zA-Z0-9]/ -- matches what. A "|" allows regular expressions to be logically OR-ed. For example: /(^Germany)|(^Netherlands)/ -- matches what. For example: /wh./ -- matches what.

a (possibly signed) integer number. /^[+-]?[0-9]+$/ -- matches any line that consists only of a (possibly signed) integer number. /^ Find string at beginning of line. /^[-+]? Specify possible "-" or "+" sign for number. /^[-+]?[0-9]+ Specify one or more digits "0" through "9". /^[-+]?[0-9]+$/ Specify that the line ends with the number.