Ngezinye izikhathi abasebenzisi babhekene nesidingo sokufuna ulwazi oluthile kunoma yimaphi amafayela. Ngokuvamile, amadokhumenti okucushwa noma enye idatha ye-volumetric iqukethe inamba enkulu yemigqa, ngakho-ke akunakwenzeka ukuthola ngesandla ukuthola idatha edingekayo. Khona-ke enye yemiyalo eyakhelwe ngaphakathi ohlelweni lwe-Linux isebenza ekusizeni, okuzokuvumela ukuba uthole izintambo ngemizuzwana embalwa nje.
Sebenzisa umyalo we-grep ku-Linux.
Ngokuqondene nokwahlukana phakathi kwemikhakha ye-Linux, kulokhu abadlali noma iyiphi indima, kusukela umyalo oyithandayo i-grep Ngokuzenzakalelayo, itholakala ezinhlanganweni eziningi futhi isetshenziswa ngokufanayo. Namuhla singathanda ukuxoxa nje ngesenzo kuphela i-grep, kodwa futhi ukuhlukanisa izimpikiswano eziyinhloko ezingahle zilulaze inqubo yokusesha.
Bheka futhi: Sifuna amafayela ku-Linux
Umsebenzi wokulungiselela
Zonke izenzo ezengeziwe zizokwenziwa nge-console ejwayelekile, futhi ikuvumela ukuvula amafayela kuphela ngokucacisa indlela ephelele kubo noma uma "Isikhumbuzo" esungulwe kusuka kuncwadi edingekayo. Ungathola ifolda yomzali wefayela bese uya kuso ku-console njengale:
- Qalisa imenenja yefayela bese uhamba kufolda oyifunayo.
- Chofoza ngakwesokudla efayeleni oyifunayo bese ukhetha "Izakhiwo".
- Kuthebhu "Okuyisisekelo" funda umugqa "Ifolda yomzali".
- Manje run "Isikhumbuzo" indlela elula, isibonelo, ngokusebenzisa imenyu noma ngokucindezela inhlanganisela yekhiye I-Ctrl + Alt + T.
- Lapha uye erekhosini nge-oda
cd / ekhaya / umsebenzisi / ifolda
kuphi umsebenzisi - igama lomsebenzisi, futhi ifolda - ifolda igama.
Yenza iqembuigama le-cat + yefayela
uma ufuna ukubuka okuqukethwe okugcwele. Imiyalo eningiliziwe yokuthi ungasebenzisa kanjani leli qembu ingatholakala kwenye i-athikili yethu kusixhumanisi esingezansi.
Funda kabanzi: Izibonelo zomyalo wekati ku-Linux
Ngokulandela izinyathelo ezingenhla, ungasebenzisa i-grep, ekukhokheni okudingekayo, ngaphandle kokucacisa indlela egcwele efayeleni.
Usesho lokuqukethwe okujwayelekile
Ngaphambi kokuqhubeka nokucubungulwa kwazo zonke izingxabano ezitholakalayo, kubalulekile ukuphawula ukuseshwa okujwayelekile ngokuqukethwe. Kuzoba usizo kulezo zikhathi lapho udinga ukuthola umdlalo olula ngenani futhi ubonise yonke imigqa efanele.
- Kumyalo wokuyala, faka
i-grep igama testfile
kuphi igama - ulwazi oludingekayo, futhi testfile - igama lefayela. Uma wenza usesho ngaphandle kwefolda, cacisa indlela egcwele elandela isibonelo./ ekhaya / umsebenzisi / ifolda / igama lefayela
. Ngemva kokufaka umyalo, cindezela ukhiye Ngena. - Kuhlala nje ukuze ujwayelane nezinketho ezitholakalayo. Imigqa egcwele iboniswa esikrinini, futhi amanani ayisihluthulelo agcizelelwe obomvu.
- Kubalulekile ukucabangela icala lezinhlamvu, ngoba ukukhokhwa kwe-Linux akulungiselelwe ukusesha ngaphandle kokucabangela izinhlamvu ezinkulu noma ezincane. Uma ufuna ukudlula incazelo yerejista, faka
i-grep -i "igama" testfile
. - Njengoba ubona, esithombeni esilandelayo, umphumela ushintshiwe futhi umugqa omusha owodwa wanezelwa.
Sesha nge-string capture
Ngezinye izikhathi abasebenzisi akudingeki ukuthi bathole umdlalo oqondile emigqeni, kodwa futhi ukuthola ulwazi oluza emva kwabo, isibonelo, uma bebika iphutha elithile. Khona-ke isisombululo esifanele ukusebenzisa izici. Ngena ku-consolei-grep -A3 "igama" testfile
ukufaka imigqa emithathu elandelayo emphumela ngemuva komdlalo. Ungabhala-A4
, khona-ke imigqa emine izothathwa, ayikho imingcele.
Uma kunalokho-A
ufaka isicelo sengxabano-B + inombolo yemigqa
, ngenxa yalokho, idatha kuze kufinyelele endaweni yokungena izoboniswa.
Ukuphikisana-C
futhi, ithatha imigqa ezungeze igama elingukhiye.
Ngezansi ungabona izibonelo zesabelo seziphakamiso ezicacisiwe. Sicela uqaphele ukuthi kubalulekile ukucabangela icala bese ubeka izingcaphuno ezimbili.
i-grep -B3 "igama" testfile
i-grep -C3 "igama" testfile
Sesha amagama angukhiye ekuqaleni nasekugcineni kwemigqa
Isidingo sokuchaza igama eliyisihluthulelo esisekuqaleni noma ekupheleni komugqa ngokuvamile kuvame ngesikhathi somsebenzi namafayela okucushwa, lapho umugqa ngamunye unesibopho sepharamitha eyodwa. Ukuze ubone ukungena ngqo ekuqaleni, udinga ukubhalisagrep "^ igama" testfile
. Uphawu ^ kuphela ophethe ukusetshenziswa kwalolu khetho.
Ukusesha okuqukethwe ekupheleni kwemigqa kwenzeka cishe emigomeni efanayo, kuphela kumaphuzu okumele ukwengeze uhlamvu $, futhi iqembu lizothola leli fomu:i-grep "elithi $" testfile
.
Sesha izinombolo
Lapho ucinga amanani afunayo, umsebenzisi akanayo ulwazi ngaso sonke isikhathi mayelana nezwi elikhona elikhona kulolu chungechunge. Khona-ke inqubo yokusesha ingenziwa ngezinombolo, ngezinye izikhathi ezilula kakhulu umsebenzi. Kudingekile kuphela ukusebenzisa umyalo owubuzwa ngesimogrep "[0-7]" testfile
kuphi «[0-7]» - uhla lwamanani, futhi testfile - igama lefayela ukuskena.
Ukuhlaziywa kwazo zonke amafayela okuqondisa
Ukuskena zonke izinto kufolda efanayo kubizwa ngokuthi kuvuselelwa. Umsebenzisi udinga ukusebenzisa ukuphikisana okukodwa kuphela, okuhlaziya wonke amafayela kufolda bese ubonisa imigqa efanelekile nendawo yabo. Uzodinga ukungenai-grep -r "igama" / ikhaya / umsebenzisi / ifolda
kuphi / ekhaya / umsebenzisi / ifolda - indlela eya kusiqondisi sokuskena.
Indawo lapho ifayela ligcinwe khona lizoboniswa ngokuluhlaza okwesibhakabhaka, futhi uma ufuna ukuthola imigqa ngaphandle kwalolu lwazi, nikeza enye ingxabano ukuze wenze umyaloI-grep -h -r "igama" + ifolda indlela
.
Ukusesha kwezwi eliqondile
Ekuqaleni kwalesi sihloko esivele sikhuluma ngokuseshwa kwegama elijwayelekile. Nokho, ngale ndlela inhlanganisela eyengeziwe izoboniswa kwimiphumela. Isibonelo, uthola igama Umsebenzisi, kodwa umyalo uzophinde ubonise Umsebenzisi123, IphasiwediUmsebenzisi nezinye izinto ezifanayo, uma kukhona. Ukuze ugweme lo mphumela, hambisa ukuphikisana-w
(grep -w "igama" + igama lefayela noma indawo
).
Lolu khetho lwenziwa ngisho noma udinga ukucinga amagama angukhiye ambalwa ngesikhathi esisodwa. Kulesi simo, fakaisibrep -w 'word1 | word2' isitifiketi
. Sicela uqaphele ukuthi kulokhu kuya i-grep kunikezwe incwadi e, futhi izingcaphuno zingashadile.
Sesha amasethingi ngaphandle kwegama elithile
Umbuso ocatshangelwe awukwazi ukuthola kuphela amafayela kumafayili, kodwa futhi ukubonisa imigqa lapho kungekho khona inani elichazwe ngumsebenzisi. Khona-ke ngaphambi kokungena kukhiye obalulekile futhi ifayela lengezwe-v
. Siyabonga, uma usebenze umyalo, uzobona idatha efanele kuphela.
I-Syntax i-grep baqoqa izingxabano ezimbalwa, okungaxoxwa ngokufushane:
-I
- bonisa kuphela amagama amafayela afana ne-criteria yokucinga;-s
- khubaza izaziso mayelana namaphutha atholakele;-n
- bonisa inombolo yezinombolo kufayela;-b
- bonisa inombolo yenombolo ngaphambi komugqa.
Akukho okukuvimbela ekusebenziseni izingxabano eziningi ekutholeni okukodwa, nje ukungena kubo ohlukaniswe isikhala, ungakhohlwa ukuthatha icala.
Namuhla siye sabhidliza inkampani ngokuningiliziwe i-grepiyatholakala kuma-Linux distributions. Ngenye yezinga futhi livame ukusetshenziswa. Ungafunda ngamanye amathuluzi athandwayo kanye ne-syntax yawo kokuqukethwe kwethu okuhlukile kusixhumanisi esilandelayo.
Bheka futhi: Izimiso ezisetshenziswa njalo kwi-Linux Terminal