UNIX operacinės sistemos Simonas Kareiva 2013 m. rudens semestras.

Slides:



Advertisements
Similar presentations
UNIX Overview. 2 UNIX UNIX is a multi-user and multi-tasking operating system. Multi-tasking: Multiple processes can run concurrently. Example: different.
Advertisements

Introduction to Linux command line for bioinformatics Wenjun Kang, MS Jorge Andrade, PhD 6/28/2013 Bioinformatics Core, Center.
EMT 2390L Lecture 4 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.
Introduction to Unix – CS 21 Lecture 13. Lecture Overview Finding files and programs which whereis find xargs Putting it all together for some complex.
UNIX Utilities Learning Objectives: 1. To understand the some basic utilities of UNIX File 2. To compare UNIX shell and popular shell 3. To learn Input/Output.
UNIX Overview. 2 UNIX UNIX is a multi-user and multi-tasking operating system. Multi-tasking: Multiple processes can run concurrently. Multi-user: different.
Unix Filters Text processing utilities. Filters Filter commands – Unix commands that serve dual purposes: –standalone –used with other commands and pipes.
UNIX Filters.
Shell Script Examples.
Advanced File Processing
June 1, 1999Manipulating Files1 Introduction to UNIX E. Manipulating Files.
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
Quality Data: Fresno State's Analytics Strategy Rob Robinson Web Developer for Fresno
LIN 6932 Unix Lecture 6 Hana Filip. LIN 6932 HW6 - Part II solutions posted on my website see syllabus.
Day 2 Review of ITSK1601 – Intro Unix.. Break up into Cousin groups Each cousin group will work as a team. Each team will need 5 blank sheets of paper.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important.
Additional UNIX Commands. 222 Lecture Overview  Multiple commands and job control  More useful UNIX utilities.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
INTRODUCTION TO LINUX Jacob Chan. GNU/Linux Consists of Linux kernel, GNU utilities, and open source and commercial applications Works like Unix –Multi-user.
School of Computer Science and Information Technology Devi Ahilya Vishwavidyalaya Shell Scripting
Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command to search for.
Introduction to Bash Programming Ellen Zhang. Previous three classes What have we learnt so far ?
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Chapter Five Advanced File Processing Guide To UNIX Using Linux Fourth Edition Chapter 5 Unix (34 slides)1 CTEC 110.
Chapter Five Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command.
Module 6 – Redirections, Pipes and Power Tools.. STDin 0 STDout 1 STDerr 2 Redirections.
Agenda Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Review next lab assignments Break Out Problems.
BIF713 Additional Utilities. Linux Utilities  You have learned many Linux commands. Here are some more that you can use:  Data Manipulation (Reg Exps)
I/O and Redirection. Standard I/O u Standard Output (stdout) –default place to which programs write u Standard Input (stdin) –default place from which.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
Chapter Four I/O Redirection1 System Programming Shell Operators.
40 Years and Still Rocking the Terminal!
UNIX History - joint venture between MIT and Bell Labs (originally called Multics) – Ken Thompson (AT&T) created an operating system to run Space.
CSCI 330 UNIX and Network Programming Unit IX: Shell Scripts.
CS252: Systems Programming Ninghui Li Slides by Prof. Gustavo Rodriguez-Rivera Topic 7: Unix Tools and Shell Scripts.
Basic of UNIX For fresh members of SPARCS
Week Two Agenda Announcements Link of the week Use of Virtual Machine Review week one lab assignment This week’s expected outcomes Next lab assignments.
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques.
UNIX commands Head More (press Q to exit) Cat – Example cat file – Example cat file1 file2 Grep – Grep –v ‘expression’ – Grep –A 1 ‘expression’ – Grep.
Lesson 6-Using Utilities to Accomplish Complex Tasks.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
+ Introduction to Unix Joey Azofeifa Dowell Lab Short Read Class Day 2 (Slides inspired by David Knox)
AWK One tool to create them all AWK Marcel Nijenhof Eth-0 11 Augustus 2010.
Unix Tools Tawatchai Iempairote November 22, 2011.
This Month's Underprepared Command Line Talk Part Three
Linux 201 Training Module Linux Adv File Mgmt.
Linux 101 Training Module Linux Basics.
Cs288 Intensive Programming in Linux
The UNIX Shell Learning Objectives:
Part 1: Basic Commands/Utilities
Chapter 6 Filters.
Unix Scripting Session 4 March 27, 2008.
Command Line Interface for Beginners
Unix Operating System (Week Two)
INTRODUCTION TO UNIX: The Shell Command Interface
Tutorial of Unix Commands
תוכניות סטנדרטיות ב-UNIX C-Shell
The Linux Command Line Chapter 6
Guide To UNIX Using Linux Third Edition
UNIX Reference Sheets CSE 2031 Fall 2010.
MeasureCamp VI *NIX for ETL
awk- An Advanced Filter
Linux Shell Script Programming
Presentation transcript:

UNIX operacinės sistemos Simonas Kareiva 2013 m. rudens semestras

Paskaita #4 awk, sed ir kiti pagalbiniai įrankiai Darbas su masyvais

Paskaita #4 – I dalis UNIX komandinės eilutės įrankių apžvalga: cut diff awk sed expand grep strings tr uniq zcat

cut > echo aa:bb cc dd:ee | cut -d : -f 2 bb cc dd > echo aa:bb cc dd:ee | cut -d " " -f 2 cc > echo aa:bb cc dd:ee | cut -d " " -f 1,2 aa:bb cc > echo aa:bb cc dd:ee | cut -d " " -f 1,2,3 aa:bb cc dd:ee > cut -d : -f 1,5 /etc/passwd | tail -3 _installer:Installer _atsserver:ATS Server _unknown:Unknown User

diff > echo "pirmas\nantras" > 1.txt > echo "pirmas\ntrecias" > 2.txt > diff 1.txt 2.txt 2c2 < antras --- > trecias > diff 1.txt 2.txt > diff.txt > patch -p0 1.txt < diff.txt patching file 1.txt > cat 1.txt pirmas trecias

expand > printf "a\tb\n" a b > printf "a\tb\n" | hexdump a > printf "a\tb\n" | expand | hexdump a a

grep > grep ^a /etc/passwd alias:*:81:81:User &:/var/qmail/alias:/nonexistent > grep ^c /etc/passwd cyrus:*:60:60:the cyrus mail server:/nonexistent:/sbin/nologin courier:*:465:465:Courier Mail System:/var/spool/courier:/sbin/nologin > grep -c nologin$ /etc/passwd 29 > tail -f httpd-error.log | grep denied [Sun Oct 4 19:18: ] [error] [client ] (13)Permission denied: cannot read directory for multi: /users/eduardas/www/ > grep -E '(error|failure)' /var/log/console | grep -vc connect_to 1945

strings > strings /var/log/wtmp | grep -A4 simonask simonask Jttypa Jttypc Jttypa > strings /bin/sync | grep error $FreeBSD: src/lib/libc/i386/sys/cerror.S,v /08/27 23:59:38 peter Exp $ error: Authentication error Exec format error Input/output error Undefined error: 0

tr > cat bug.lt | tr e 3 W3 ar3 us3r group of BSD syst3ms. Th3 group was 3stablish3d in th3 summ3r of It happ3n3d in small city of North Lithuania. > cat bug.lt | tr '[a-z]' '[A-Z]' WE ARE USER GROUP OF BSD SYSTEMS. THE GROUP WAS ESTABLISHED IN THE SUMMER OF IT HAPPENED IN SMALL CITY OF NORTH LITHUANIA.

uniq > grep DNS ppp.log | awk '{ print $10 }' | sort | uniq > grep Illegal cache.log | tail /10/04 19:37:34| urlParse: Illegal character in hostname 'www,youtube.lt’ > grep Illegal cache.log | cut -d " " -f 8 | sort | uniq -c | sort - rn | head 760 '[2a01:138:a001:201:' 57 '2a01%3a138%3aa001%3a201%3a%3a24' 57 '2a01%3a138%3aa001%3a201%3a%3a23' 57 '2a01%3a138%3aa001%3a201%3a%3a22' 57 '2a01%3a138%3aa001%3a201%3a%3a21' 12 '%20ssl.google-analytics.com' 7 'www,youtube,com' 4 'evi � ka-pc' 3 'www,youtube.lt' 3 'vista.%20liedm.lt’

zcat > cat > test2.sh #!/bin/sh echo date exit 0; > gzip test2.sh > cat test2.sh.Z ;??Jtest2.shSV?O???/??JM??WHI,I?J??,Q0???d?I> > zcat test2.sh.Z #!/bin/sh echo date exit 0;

sed > echo diena | sed s/diena/naktis/ naktis > echo "123 abc" | sed 's/[0-9]*/& &/' abc > echo kaire desine | sed 's/\([a-z]*\) \([a-z]*\)/\2 \1/' desine kaire > sed '/start/,/stop/ s/#.*//' ?

sed Palyginkite: sed 's/\([a-zA-Z]*\) \([a-zA-Z]*\) /\1 /' sed 's/[a-zA-Z]* //2' sed 's/./&:/20' sed 's/^ /&:/' sed -n 's/jonas/&/p' <file grep jonas file sed 'y/abcdef/ABCDEF/’ tr abcdef ABCDEF

sed #!/bin/sh sed -n ' /begin/,/end/ { s/#.*// s/[ ^I]*$// /^$/ d p } ’

sed #!/bin/sh # Tokiu budu isvalome eilutes kurios prasideda # # (komentarus) tarp zodziu ‘begin’ ir ‘end’ sed -n ' /begin/,/end/ { s/#.*// s/[ ^I]*$// /^$/ d p } '

sed (advanced) > cat cat.txt This is my cat my cat's name is betty This is my dog my dog's name is frank > sed 'N;s/\n / /;P;D;' cat.txt This is my cat my cat's name is betty This is my dog my dog's name is frank N - pridedame sekančią eilutę prie darbinio buferio s - keitimas /\n / - naujos eilutės ir tarpo atitikimas / / - keičiamas į vieną tarpą P - atspausdina pirmą buferio eilutę D ištrina pirmą buferio eilutę ir tęsia darbą

awk > ls -l 1 simonask staff Rgs 14 15:59 UNIX_1.pps > ls -l | awk ' BEGIN { print ”Byla\t\tSavininkas" } { print $9, "\t\t", $3} END { print " - DONE -" } ' BylaSavininkas UNIX_1.pps simonask - DONE - > date Sekmadienis, 2009 m. spalio 4 d. 20:21:58 EEST > date | awk '{print $1}' Sekmadienis, > date | awk '{print $2}' 2009

awk BEGIN { print ”ivesk skaiciu"; } { print ”Skaiciaus ", $1, ” kvadratas yra ", $1*$1; print ”ivesk dar viena skaiciu"; } END { print ”Ate" }

awk awk '{print $2, $1}' skaityk.txt awk '{print NR "\t" $0}’ skaityk.txt awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' Palyginkite: head -10 awk 'NR < 11’ awk '!/paieska/' skaityk.txt grep –v paieska skaityk.txt

užduotys ls -d *.sh | sed 's/\(.*\).sh$/cp "&" \1/' | sh ____________________________________________________________ STR="`sed <<<"$STR" "s/\\\\(.\\\\)/\\\\1('\\\\\\\\s*\\\\\\\\+\\\\\\\\s*')?/g;s/( '\\\\\\\\s\\\\*\\\\\\\\+\\\\\\\\s\\\\*')?$//"`" ____________________________________________________________ find ${1-.} -type d -print | env LC_ALL='C' sort -if | sed-e "s,^${1-.},," \ -e "/^$/d" \ -e "s,[^/]*/\([^/]*\)$,\`-----\1," \ -e "s,[^/]*/,|,g"

Spec. kintamieji $0 pačios komandos pavadinimas. $# pateiktų argumentų skaičius $? prieš tai dirbusio proceso išėjimo būsena $$ šio interpretatoriaus proceso numeris $! paskutinio foninio PID numeris $- dabartinio interpretatoriaus paleisties parametrai $* visi parametrai, pradedant nuo $1. ir $*, tik naudojamas kabutėse

/bin/sh masyvai area[11]=23 area[13]=37 area[51]=UFOs echo ${area[11]}

Operacijos su masyvais area[5]=`expr ${area[11]} + ${area[13]}` area[6]=`expr ${area[11]} + ${area[51]}` Kur klaida?

Kiti būdai area2=( nulis vienas du trys keturi ) echo ${area2[0]} area3=([17]=septyniolika [24]=dvidesimtketuri) array1=( `cat "$filename" | tr '\n' ' '`) read -a colors base64_charset=( {A..Z} {a..z} {0..9} + / = )

Tipo nėra string=abcABC123ABCabc echo # abcABC123ABCabc echo ${string[*]} # abcABC123ABCabc echo ${string[0]} # abcABC123ABCabc echo ${string[1]} # echo # 1

Prisiminkime ir pritaikykime array= ( nulis vienas du trys keturi penki ) # Elementai: echo ${array[0]} # nulis echo ${array:0} # nulis echo ${array:1} # ulis echo ${#array[0]} # 5 echo ${#array} echo ${#array[1]} # 6 echo ${#array[*]} # 6 echo # 6

Operacijos su eilutėmis arrayZ=( one two three four five five ) echo # one two three four five five echo # two three four five five echo # two three echo # one two three five five echo # one two four five five echo # one two t four five five echo # one two four five five

Elementų keitimas (replacement) echo # one two four five five echo # one two three four fYYe fYYe echo # one two three four ve ve echo one two three four XYve Xyve echo # one two three four fiZZ fiZZ echo # one twXX three four five five

Skaidrė #5 – naudingi scenarijai Praktiniai pavyzdžiai kaip išgauti naudos iš scenarijų Kai kuriuos dažnai naudoja ir dėstytojas Atkreipkite dėmesį, jog naudojami įvairūs išoriniai įrankiai

singleton #!/bin/bash echo "argument: $1" RESULT=`/bin/ps xauwww | /bin/grep -v "$0" | /bin/grep "^$USER.*$1$"` if [ -z "$RESULT" ] ; then LC_MESSAGES=en_US $* else echo "Sorry, already running as:" echo " $RESULT” echo "singleton reports that $1 is already started” fi #end

mysqltcpdump # tcpdump -i eth0 -s 0 -l -w - dst port 3306 | strings | perl -e ' while(<>) { chomp; next if /^[^ ]+[ ]*$/; if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CRE ATE|DROP|ALTER)/i) { if (defined $q) { print "$qn"; } $q=$_; } else { $_ =~ s/^[ t]+//; $q.=" $_"; } }'

wipeout #!/bin/bash time=" :00" reffile=wipeout.ref.$RANDOM touch -d "$time" $reffile echo echo Deletes all dirs that are older than $time echo find. -type d -maxdepth 1 -path './*' ! -newer $reffile | while read dir; do echo rm -rf "$dir" rm -rf "$dir" done rm -f $reffile

ts2date !#/bin/bash #EPOCH=$1 EPOCH= DATE=$(perl -e “require ‘ctime.pl’; print &ctime($EPOCH);”) echo $DATE DATE=$(perl -e “print scalar(localtime($EPOCH))”) echo $DATE DATE=$(echo $EPOCH|awk ‘{print strftime(”%c”,$1)}’) echo $DATE

mrename ls -d *.php3 | \ sed 's/\(.*\).php3$/mv "&" "\1.php"/' | \ sh

#!/usr/bin/perl -w # camel code use strict; $_='ev al("seek\040D ATA,0, 0;");foreach(1..3) { my$Camel ;while( ){$_=sprintf("%-6 1=split(//);if(defined($ _= ry1){my$camel1hump=0 ;my$CAMEL=3;if(defined($_=shif ))&&/\S/){$camel1hump+=1<<$CAMEL;} $CAMEL--;if(d $camel1hump+=1 L;;}$camel.=(split(//,"\040..m`{/J\047\134}L^7FX"))[$camel1h camel1hump){chomp;$Camel=$_;y/LJF7\173\175`\047/\061\062\063\ 064\065\066\067\070/;y/ /JL7F\175\173\047`/;$_=reverse; /LJF7\173\175`\047/ /;y/ /JL7F\175\173\0 47`/; $_=reverse;print"\040$_$Camel\n";}';;s/\s*//g;;eval; eval ("seek\040DATA,0,0;");undef$/;$_= ;s/\s*//g;( );;s ;^.*_;;;map{eval"print\"$_\"";}/.{4}/g; __DATA__ \124 \1 50\145\040\165\163\145\040\157\1 46\040\1 41\0 40\143\141 \155\145\1 54\040\1 51\155\ 141 \147\145\0 40\151\156 \040\141 \163\16 3\ 157\143\ 151\141\16 4\151\1 57\156 \040\167 \151\164\1 50\040\ 120\1 45\162\ 154\040\15 1\163\ 040\14 1\040\1 64\162\1 41\144 \145\ 155\14 1\162\ 153\04 0\157 \146\ 040\11 7\047\ 122\1 45\15 1\154\1 54\171 \040 \046\ 012\101\16 3\16 3\15 7\143\15 1\14 1\16 4\145\163 \054 \040 \111\156\14 3\056 \040\ 125\163\145\14 4\040\ 167\1 51\164\1 50\0 40\160\ 145\162 \155\151 \163\163 \151\1 57\156\056