Kwenye Unix, "kila kitu ni mafaili na pipelines"


x0rz

x0rz

Member
Joined
Nov 11, 2017
Messages
81
Points
125
x0rz

x0rz

Member
Joined Nov 11, 2017
81 125
Habari, Jumuiya Unix JF!

unix-jpg.1024298


Baada ya kitambo kidogo, nimekuja na jambo kidogo la kufumbuana ufahamu kidogo kwa habari ya Unix. Ni concept moja katika Unix ambayo wachache walio bahatika ndio wanaoijua, na inafaida sana kuifahamu, wewe kama mtumiaji wa Unix wa kawaida na hata sisi Hackers. Hivo nitakwenda kuanza kufafanua concept hiyo.

Kuna concepts nyingi sana katika Unix ambazo zinavutia sana kufahamu, mojawapo ni ile maarafu iitwayo "everything is a file" design, ambapo device drivers, directories, system configuration, kernel parameters, na processes zote zinakuwa zinatambulishwa kama mafaili katika filesystem.

Kila kitu, iwe ni faili la plain-text (kwa mfano, /etc/hosts), a block or character special device driver (kwa mfano /dev/sda), au kernel state na configuration (kwa mfano, /proc/cpuinfo) inatambulishwa kama faili.

Uwepo wa pipes unapelekea kuwepo na mfumo ambapo tools zinaandikwa kudhania kwamba zitakuwa zikifanyia kazi mikondo ya maandishi, na hakika configuration nyingi za mfumo ziko katika mfumo wa maandishi pia. Mafaili ya configuration yanaweza kupangiliwa, kutafutwa, kureformatiwa na hata kuchambuliwa na kuunganishwa, zote kwa kutumia tools zinazopatikana katika Unix.

Concept ya "everything is a file" na operation nne za (open, close, read, write) ambazo zinapatikana kwenye faili inamaanisha kwamba Unix inatupa design safi na rahisi sana. Shell scripts zenyewe ni mfano mwingine wa utility ya mfumo ambayo pia iko katika mfumo wa maandishi. Inamaanisha kwamba unaweza kuandika programs kama hivi:

Code:
#!/bin/sh
cat $0
echo "---"
tac $0
Code hii inatumia tool inaitwa cat, ambayo kazi yake ni kutoa output ya file, na tool inayoitwa tac, ambayo inafanya sawa na cat lakini enyewe inafanya kinyume chake. (Kama jinsi ata jina lake lilivyo kinyume cha cat.) Variable $0 ni variable special, inayotambulika na mfumo, na inabeba jina la program inayo-run kwa wakati huo, punde tu inapoitwa-variable hiyo.

Output ya command hiyo ni kama ifuatavyo:

#!/bin/sh
cat $0
echo "---"
tac $0
---
tac $0
echo "---"
cat $0
#!/bin/sh

Mistari minne ya mwanzo ni matokeo ya cat, mstari wa tano ni matokeo ya echo, na mistari minne ya mwisho ni output ya tac.

Asante sana, kwa kuchukua muda wako kujifunza concept hii katika Linux. Karibu tena siku nyingine tujifunze.

[ x ] HackerHub | Forum Board
 
Pancras Suday

Pancras Suday

Verified Member
Joined
Jun 24, 2011
Messages
7,697
Points
2,000
Pancras Suday

Pancras Suday

Verified Member
Joined Jun 24, 2011
7,697 2,000
Kijana unajiita "Hacker". Umesha hack nn hadi sasa
Ana haki ya kujiita hacker, maana hata script kiddie nao hujiita hacker, hacker ni neno pana sana mkuu


Sent from my iPhone using JamiiForums
 

Forum statistics

Threads 1,295,692
Members 498,334
Posts 31,219,944
Top