Presentation is loading. Please wait.

Presentation is loading. Please wait.

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?

Similar presentations


Presentation on theme: "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?"— Presentation transcript:

1 Exam Revision

2 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).

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

4 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

5 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

6 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

7 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

8 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 110 100 100 which is interpreted as rw- r-- r-- – chmod 777 progress.txt 777 is 111 111 111 which is interpreted rwx rwx rwx – chmod 400 progress.txt 400 is 100 000 000 which is interpreted as r-- --- --- Setting and changing permissions – chmod (2)

9 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

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

11 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.

12 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.

13 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)

14 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

15 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>

16 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

17 Killing Processes Use top Alternatively, use kill – kill E.g. kill -15 25718 – “-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.

18 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 %

19 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

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

21 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

22 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 { }

23 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

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

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

26 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 http://www.vectorsite.net/tsawk_1.html#m1

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

28 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.

29 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.


Download ppt "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?"

Similar presentations


Ads by Google