In Unix, “Everything is a file” and pipelines.

Here you discuss Batch language & Shell Scripting...
User avatar
xpl0it
Admin
Admin
Posts: 113
Joined: Mon May 08, 2017 1:36 am
Location: 127.0.0.1
x 31
x 8
Contact:

In Unix, “Everything is a file” and pipelines.

#1

Unread post by xpl0it » Sat Feb 16, 2019 8:24 pm

Hello, HackerHub!

unix.jpg
Unix
unix.jpg (60.33 KiB) Viewed 65 times

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: Select all

#!/bin/sh
cat $0
echo "---"
tac $0
Code hii inatumia tool inaitwa cat, ambayo kazi yako ni kutoa output ya file, na tool inayoitwa tac, ambayo inafanya sawa na cat lakini enyewe inafanya kinyume. (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.
0 x

Tags:

User avatar
nirmitpatel
Noob
Noob
Posts: 1
Joined: Fri Mar 08, 2019 9:10 am

Re: In Unix, “Everything is a file” and pipelines.

#2

Unread post by nirmitpatel » Fri Mar 08, 2019 9:33 am

Great Thanks for this great post.very well done. :) keep posting. and share more details to linux
0 x

User avatar
xpl0it
Admin
Admin
Posts: 113
Joined: Mon May 08, 2017 1:36 am
Location: 127.0.0.1
x 31
x 8
Contact:

Re: In Unix, “Everything is a file” and pipelines.

#3

Unread post by xpl0it » Wed Mar 13, 2019 6:47 am

Thanks mate,,, Welcome again @nirmitpatel
0 x

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest