lecture 7: file i/o, more unixix.cs.uoregon.edu/~hank/330/lectures/cis330_s18_lec7.pdf · through...
TRANSCRIPT
![Page 1: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/1.jpg)
Hank Childs, University of OregonApril 18th, 2018
CIS 330:_ _ _ _ ______ _ _____
/ / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __/ / / / __ \/ / |/_/ / __ `/ __ \/ __ / / / _/_// / __/ /___/ /_/ /_/ / / / / /> < / /_/ / / / / /_/ / / /____/_/ / /__/_ __/_ __/\____/_/ /_/_/_/|_| \__,_/_/ /_/\__,_/ \____/_/ \____//_/ /_/
Lecture 7: file I/O, more Unix
![Page 2: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/2.jpg)
Announcements
• Projects– 4AdueINCLASSFriday(nolate)– 2Bassignedtoday,dueMonday– 3A,2Ctobeassignedsoon
• Nextweek:– LectureMondayandFriday– LabWednesday– Also,willbeaYouTubeshortlecture
• (Wearegettingaheadofschedule… tryinghardtopreventworkfromthisclasstobebackloaded)
![Page 3: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/3.jpg)
Outline
• Review• FileI/O• Project2B• Redirection• Pipes
![Page 4: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/4.jpg)
Outline
• Review• FileI/O• Project2B• Redirection• Pipes
![Page 5: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/5.jpg)
Makefile example:multiplierlib
![Page 6: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/6.jpg)
Unixcommand:tar
• tarcvf 330.tarfile1file2file3– puts3files(file1,file2,file3)intoanewfilecalled330.tar
• scp 330.tar@ix:~• ssh ix• tarxvf 330.tar• ls
file1file2file
![Page 7: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/7.jpg)
MemoryErrors
• Arrayboundsread
• Arrayboundswrite
![Page 8: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/8.jpg)
MemoryErrors
• Freememoryread/freememorywrite
Vocabulary:“danglingpointer”:pointerthatpointstomemorythathasalreadybeenfreed.
![Page 9: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/9.jpg)
MemoryErrors
• Freeingunallocatedmemory
![Page 10: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/10.jpg)
MemoryErrors
• Freeingnon-heapmemory
![Page 11: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/11.jpg)
MemoryErrors
• NULLpointerread/write
• NULLisneveravalidlocationtoreadfromorwriteto,andaccessingthemresultsina“segmentationfault”– ….rememberthosememorysegments?
![Page 12: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/12.jpg)
MemoryErrors
• Uninitializedmemoryread
![Page 13: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/13.jpg)
NEW:IPR,IPW
• int *X=0xDEADBEEF:• int Y=*X;
• whaterrorcodefits?
• Imissedtwo:– InvalidPointerRead(IPR)– InvalidPointerWriter(IPW)
![Page 14: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/14.jpg)
Memoryerrorinaction
![Page 15: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/15.jpg)
Project4A
• Postednow• Youwillpracticedebugging&usingadebugger– Thereare3programsyouneedtodebug
• Inthiscase,“debug”meansidentifythebug– Doesnotmeanfixthebug
• Canusegdb orlldb• Maywanttorunonix
• WorksheetdueinclassFriday• P3.c:4errors
![Page 16: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/16.jpg)
Outline
• Review• FileI/O• Project2B• Redirection• Pipes
![Page 17: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/17.jpg)
FileI/O:streamsandfiledescriptors
• Twowaystoaccessfiles:– Filedescriptors:• Lowerlevelinterfacetofilesanddevices
– Providescontrolstospecificdevices
• Type:smallintegers(typically20total)
– Streams:• Higherlevelinterfacetofilesanddevices
– Providesuniforminterface;easytodealwith,butlesspowerful
• Type:FILE*
Streamsaremoreportable,andmoreaccessibletobeginningprogrammers.(Iteachstreamshere.)
![Page 18: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/18.jpg)
FileI/O
• Processforreadingorwriting– Openafile• TellsUnixyouintendtodofileI/O• Functionreturnsa“FILE*
– Usedtoidentifythefilefromthispointforward
• Checkstoseeifpermissionsarevalid
– Readfromthefile/writetothefile– Closethefile
![Page 19: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/19.jpg)
Openingafile
• FILE*handle=fopen(filename,mode);
Example:FILE*h=fopen(“/tmp/330”,“wb”);
Note:#include<stdio.h>
Closewhenyouaredonewith“fclose”
![Page 20: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/20.jpg)
Reading/Writing
![Page 21: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/21.jpg)
Example
![Page 22: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/22.jpg)
FilePositionIndicator
• Filepositionindicator:thecurrentlocationinthefile
• IfIreadonebyte,theonebyteyougetiswherethefilepositionindicatorispointing.– Andthefilepositionindicatorupdatestopointatthenextbyte
– Butitcanbechanged…
![Page 23: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/23.jpg)
fseek
![Page 24: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/24.jpg)
ftell
![Page 25: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/25.jpg)
Wehaveeverythingweneedtomakeacopycommand…
• fopen• fread• fwrite• fseek• ftell
Canwedothistogetherasaclass?
![Page 26: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/26.jpg)
argc &argv
• twoargumentstoeveryCprogram• argc:howmanycommandlinearguments• argv:anarraycontainingeachofthearguments
• “./a.out hankchilds”• à argc ==3• à argv[0]=“a.out”,argv[1]=“hank”,argv[2]=“childs”
![Page 27: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/27.jpg)
![Page 28: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/28.jpg)
Returnvaluesinshells
$?isthereturnvalueofthelastexecutedcommand
![Page 29: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/29.jpg)
Printingtoterminalandreadingfromterminal
• InUnix,printingtoterminalandreadingfromterminalisdonewithfileI/O
• Keyboardandscreenarefilesinthefilesystem!– (atleasttheywere…)
![Page 30: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/30.jpg)
StandardStreams
• Wikipedia:“preconnected inputandoutputchannelsbetweenacomputerprogramanditsenvironment(typicallyatextterminal)whenitbeginsexecution”
• Threestandardstreams:– stdin (standardinput)– stdout (standardoutput)– stderr (standarderror)
WhatmechanismsinCallowyoutoaccessstandardstreams?
![Page 31: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/31.jpg)
printf
• Printtostdout– printf(“helloworld\n”);– printf(“Integersarelikethis%d\n”,6);– printf(“Twofloats:%f,%f”,3.5,7.0);
![Page 32: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/32.jpg)
fprintf
• Justlikeprintf,buttostreams• fprintf(stdout,“helloworld\n”);–à sameasprintf
• fprintf(stderr,“helloworld\n”);– printsto“standarderror”
• fprintf(f_out,“helloworld\n”);– printstothefilepointedtobyFILE*f_out.
![Page 33: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/33.jpg)
bufferingandprintf
• Important:printf isbuffered• So:– printf putsstringinbuffer– otherthingshappen– bufferiseventuallyprinted
• Butwhataboutacrash?– printf putsstringinbuffer– otherthingshappen…includingacrash– bufferisneverprinted!Solutions:(1)fflush,(2)fprintf(stderr)alwaysflushed
![Page 34: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/34.jpg)
Outline
• Review• FileI/O• Project2B• Redirection• Pipes
![Page 35: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/35.jpg)
Project2B
0 1
![Page 36: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/36.jpg)
Outline
• Review• FileI/O• Project2B• Redirection• Pipes
![Page 37: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/37.jpg)
Unixshellsallowsyoutomanipulatestandardstreams.
• “>”redirectoutputofprogramtoafile• Example:– ls >output– echo“thisisafile”>output2– catfile1file2>file3
![Page 38: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/38.jpg)
Unixshellsallowsyoutomanipulatestandardstreams.
• “<”redirectfiletoinputofprogram• Example:– python<myscript.py• Note:pythonquitswhenitreadsaspecialcharactercalledEOF(EndofFile)• YoucantypethischaracterbytypingCtrl-D• ThisiswhyPythonquitswhenyoutypeCtrl-D
– (manyotherprogramstoo)
![Page 39: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/39.jpg)
Unixshellsallowsyoutomanipulatestandardstreams.
• “>>”concatenateoutputofprogramtoendofexistingfile– (orcreatefileifitdoesn’texist)
• Example:– echo“Iamstartingthefile”>file1– echo“Iamaddingtothefile”>>file1– catfile1
IamstartingthefileIamaddingtothefile
![Page 40: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/40.jpg)
What’shappeninghere?
ls isoutputtingitserrormessagestostderr
![Page 41: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/41.jpg)
Redirectingstderr inashell
![Page 42: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/42.jpg)
Redirectingstderr tostdout
Convenientwhenyouwantbothtogotothesamestream
![Page 43: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/43.jpg)
Outline
• Review• FileI/O• Project2B• Redirection• Pipes
![Page 44: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/44.jpg)
cfunctions:forkandpipe• fork:duplicatescurrentprogramintoaseparateinstance– Tworunningprograms!– Onlydifferentiatedbyreturnvalueoffork(whichisoriginalandwhichisnew)
• pipe:mechanismforconnectingfiledescriptorsbetweentwoforkedprograms
Throughforkandpipe,youcanconnecttworunningprograms.Onewritestoafiledescriptor,andthe
otherreadstheoutputfromitsfiledescript
Onlyusedonspecialoccasions.(Andoneofthoseoccasionsiswiththeshell.)
![Page 45: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/45.jpg)
pipesinUnixshells
• representedwith“|”• outputofoneprogrambecomesinputtoanotherprogram
![Page 46: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/46.jpg)
Veryusefulprograms
• grep:keeplinesthatmatchpattern,discardlinesthatdon’tmatchpattern
![Page 47: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/47.jpg)
Veryusefulprograms
• sed:replacepattern1withpattern2– sed s/pattern1/pattern2/g• smeanssubstitute• gmeans“global”…everyinstanceontheline
sed isalsoavailablein“vi”:%s/pattern1/pattern2/g(%meansalllines)
:103,133s/p1/p2/g(lines103-133)
![Page 48: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/48.jpg)
Wildcards
• ‘*’isawildcardwithunix shells
‘?’isawildcardthatmatchesexactlyonecharacter
![Page 49: Lecture 7: file I/O, more Unixix.cs.uoregon.edu/~hank/330/lectures/CIS330_S18_Lec7.pdf · Through fork and pipe, you can connect two running programs. One writes to a file descriptor,](https://reader034.vdocuments.site/reader034/viewer/2022050415/5f8b475abf5c317fdd55c895/html5/thumbnails/49.jpg)
Otherusefulshellthings
• ‘tab’:auto-complete• esc=:showoptionsforauto-complete• Ctrl-A:gotobeginningofline• Ctrl-E:gotoendofline• Ctrl-R:searchthroughhistoryforcommand