Menene / dev / null kuma ta yaya zai taimake ku?

Idan har muna da wasu ra'ayoyi game da bishiyar GNU / Linux, aƙalla ya kamata mu saba da / dev / reference, wanda shine ingantaccen inda duk fayilolin da suka shafi na'urorin haɗi.

Idan muka duba cikin kundin adireshi / dev / za mu ga "fayil" da ake kira null, amma idan muna so mu bude shi don ganin abin da ke ciki, tsarin zai gaya mana cewa ba zai yiwu ba tunda ba abun ciki bane na yau da kullun. Na sanya kalmar fayil saboda, kamar yadda duk kuka sani don Linux komai (kayan aiki da software) ana wakilta azaman fayil.

Wannan gudummawa ce daga Daniel Durante, don haka ya zama ɗayan waɗanda suka yi nasara a gasarmu ta mako:Raba abin da ka sani game da Linux«. Taya murna Daniyel!

Wace na'ura ce / dev / null tayi dace da ita?

Don dalilai masu amfani, yi tunanin kwandon shara, rami mara ƙasa ko sararin samaniya wanda za'a jefa komai ba tare da yiwuwar dawo da shi ba (komai irin wahalar da samarin NASA suka yi).

Amma idan na riga ina da umarni kamar rm, me yasa nake son sabon abu in share?

Saboda yadda dukkan “bakaken ramuka” suke aiki ya banbanta sosai: ta yaya zaku bi diddigin tsarin fitowar kuskure a cikin umarni a cikin rubutun harsashi a lokacin gudu? Anan ne / dev / null ya shigo.

Bari mu ganta da misali.

Mun ƙirƙiri fayil ɗin da ake kira gwaji wanda ke ɗauke da kirtani "Sannu Duniya". Idan muna son wakiltar abun cikin wannan fayil ɗin akan layin umarni, za mu iya yin hakan ta hanyar mai zuwa:

mai amfani @ kwamfutar tafi-da-gidanka: ~ $ gwajin cat
Sannu Duniya

Idan fayil ɗin bai wanzu ba ko kuma aka lasafta shi azaman gwaji (tare da 's' a ƙarshen), za mu sami kuskuren mai zuwa a cikin na'ura mai kwakwalwa:

mai amfani @ kwamfutar tafi-da-gidanka: ~ $ jarabawar cat
cat: gwaje-gwaje: Fayil ko kundin adireshi babu

Me za mu iya yi don kauce wa saƙon kuskure? Da kyau, kawai a tura fitowar umarnin, idan akwai kuskure, zuwa "kwandon shara", wannan shine / dev / null

Ta yaya zamu tantance shi don ya kasance idan akwai kuskure? Anan kuka shigar da daidaitattun shigarwar, fitarwa, da ƙimar kuskure don shirin: STDIN, STDOUT, da STDERR (wanda za'a iya maye gurbin su 0, 1, da 2 bi da bi). Ta wannan hanyar, idan muka sanya ...

mai amfani @ kwamfutar tafi-da-gidanka: ~ $ cat gwaji 2> / dev / null
mai amfani @ kwamfutar tafi-da-gidanka: ~ $

Will Za mu ga cewa ba za a samar da kuskuren sakon a kan na'urar ba.

Dole ne ku yi hankali saboda rubutun yana da mahimmanci: tsakanin haruffa 2 da> bai kamata a sami sarari ba. In ba haka ba, zai ba da masu zuwa:

mai amfani @ kwamfutar tafi-da-gidanka: ~ $ cat gwaji 2> / dev / null
cat: gwaje-gwaje: Fayil ko kundin adireshi babu
cat: 2: Fayil ko kundin adireshi babu

Sabanin haka, sarari tsakanin> da / dev / null ba zai tasiri mummunan sakamakon ba.

Haka nan za mu iya amfani da karkatar da kuskure, misali, don kama kurakurai a cikin fayil ɗin rajista kamar haka:

mai amfani @ kwamfutar tafi-da-gidanka: ~ $ cat gwaji 2> err.log

Wata shari'ar mai ban sha'awa ita ce tarin sakamako a cikin wani fayil ɗin muddin ba a sami kuskure ba, wanda za mu sanya:

mai amfani @ kwamfutar tafi-da-gidanka: ~ $ gwajin cat 1> output_result 2> err.log

A ƙarshe, ya zama dole a sanya kalmar "> / dev / null 2> & 1" wacce a ciki ake hada daidaitaccen fitarwa da kuma fitowar kuskure, ana tura su ta yadda ba yadda za a sami bayanan fitarwa.


Abubuwan da ke cikin labarin suna bin ka'idodinmu na ka'idojin edita. Don yin rahoton kuskure danna a nan.

8 comments, bar naka

Bar tsokaci

Your email address ba za a buga.

*

*

  1. Mai alhakin bayanan: Miguel Ángel Gatón
  2. Dalilin bayanan: Gudanar da SPAM, gudanar da sharhi.
  3. Halacci: Yarda da yarda
  4. Sadarwar bayanan: Ba za a sanar da wasu bayanan ga wasu kamfanoni ba sai ta hanyar wajibcin doka.
  5. Ajiye bayanai: Bayanin yanar gizo wanda Occentus Networks (EU) suka dauki nauyi
  6. Hakkoki: A kowane lokaci zaka iyakance, dawo da share bayanan ka.

  1.   Guido Ignatius Ignatius m

    Ah, amma ɗayan abubuwanda aka fi amfani dasu waɗanda / dev / null suke dasu sun ɓace, wanda shine wofintar da fayiloli: $ cat / dev / null> file.log Ta wannan hanyar, fayil ɗin.log din zai zama fanko. Itara shi!

    1.    Eduardo H. m

      Daidai ne bayanin da yake nema.
      Na goyi bayan motsi don ƙarawa =)

      Na gode!

  2.   Pablo m

    Sannu, da farko dai labarin yana da kyau sosai! na biyu Ina so in ba da gudummawar wani abu tare da wannan haɗin kan batun cron aiki a cikin php daga Cpanel kuma na uku taya murna ga blog!

  3.   Pablo m

    Labari mai kyau akan dev / null, abin kunya ina tsammanin nayi kuskure nayi tsokaci a wurin da ba daidai ba kafin! na tuba

  4.   m m

    na gode kyakkyawar gudummawa

  5.   Jar m

    Gaisuwa ina samun harin kai tsaye. Ina amfani da andrirc kuma na sami sirri daga laƙabi na da kalmar Null. Bayan dakika 2 shirin ya rufe Ina karantawa kuma daga abin da na ga wannan Shell ne kawai zai iya aiwatar da shi, ba wani na waje ba. Nayi kokarin watsi da kaina / watsi -lrpcntikd kuma Babu abin da yake bani mamaki umarnin yana ci gaba da zuwa. Idan kuna da wata hanyar da zaku gwada toshe ta zan yaba da ita. Murna

  6.   Sofia martinez m

    Menene zai faru idan lokacin zartar da hukuncin ba a sanya alamar>?

    Shin wani zai iya min jagora don Allah?

  7.   Nil m

    Barka da safiya, na shigar da Debian netinst a ACER Extensa 5620Z - 32 bit. Da zarar an gama shigarwa daga kebul na USB kuma an cire pendrive don ya tashi daga diski mai wuya (kada ku sake sakawa daga alkalami) amma a lokacin booting. tsarin da ta tambaye ni:
    Debian shiga: xxxxxxxx (ok)
    Kalmar wucewa: xxxxxxxx (ok)
    nil@debian:~$ ???? menene wannan? Me zan saka a wurin?

    Ba tare da wannan umarnin ba ba zan iya ci gaba da boot ɗin tsarin ba.
    Za'a iya taya ni? Ban san yadda zan ci gaba ba.
    Na gode sosai. Gaisuwan alheri.