16 Nisan 2018 Pazartesi

/dev/null Özel Dosyası

Giriş
/dev/null bir dosya veya uygulama değil. Kendisi bir character device. Görmek için şöyle yaparız.
$ file /dev/null
/dev/null: character special (3/2)
Düzgün çalışan bir sistemde bu dosya her zaman yazılabilir olmalı.
ls -l /dev/null
 crw-rw-rw- 1 root root 1, 3 Jul 20  2017 /dev/null
/dev/zero bu device'ın kardeşi sayılır. Açıklaması şöyle
The following devices must exist under /dev.

/dev/null
  All data written to this device is discarded. A read from this device will return an EOF condition.

/dev/zero
  This device is a source of zeroed out data. All data written to this device is discarded. A read from     this device will       return as many bytes containing the value zero as was requested.
/dev/null yerine /dev/zero dosyasına yazarsak ne olur ?
Açıklaması şöyle. Yani aynı sonucu elde ederiz ve veri dikkate alınmaz, ancak geleneksel yöntem bu değil.
If you're using Linux, it's never "mandatory" to redirect to /dev/null instead of /dev/zero. As you've noticed, you'll get the same result either way.

That said, you should always redirect to /dev/null if you're discarding data. Because everyone understands that writing to /dev/null means throwing the data away; it's expressing your intention.

On the other hand, writing to /dev/zero also throws your data away, but it's not immediately obvious that that's what you're trying to do.

Hiç yorum yok:

Yorum Gönder