Output Redirection - Standard Input, Standard Output, Standard Error, /dev/null
- Categories:
- tutorial
Di dunia Linux atau macOS, /dev/null
adalah seperti lubang hitam bagi data. Apapun hasil yang di-pipe ke situ akan hilang tanpa bekas.
Menggunakan > /dev/null 2>&1
akan mengarahkan semua output (baik stdout
maupun stderr
) ke /dev/null
, sehingga tidak dicetak ke terminal.
Jadi standar input, output, dan error pada shell:
- stdin => fd 0 (default)
- stdout => fd 1 (default)
- stderr => fd 2 (default)
Saat menjalankan perintah > /dev/null
, maka:
- stdin => fd 0 (tetap)
- stdout => dialihkan ke
/dev/null
- stderr => fd 2 (tetap)
Kemudian 2>&1 /dev/null
akan mengarahkan:
- stdin => fd 0 (tetap)
- stdout => tetap
/dev/null
- stderr => dialihkan ke
stdout
File descriptor (fd) adalah handle unik yang mengarah pada suatu file atau resource lain di sistem operasi. Setiap proses memiliki akses ke fd 0 (stdin), fd 1 (stdout), dan fd 2 (stderr) sebagai cara untuk membaca dan menulis ke suatu resource.
Referensi: redirecting to /dev/null
Recent Posts
AWS Secrets Manager
Explanation about AWS Secrets Manager with example code.
Envelope Encryption
Envelope encryption is the practice of encrypting plaintext data with a data key, and then encrypting the data key under another key.
Tutorial - "su username vs su - username" - A Security Perspective
The main difference between `su username` and `su - username` lies in the environment variables that are loaded when switching to the specified user.
Subdomain Hijacking
My dormant subdomain was recently hijacked, redirecting it to a online gamble registration page.
C# DbContext ServiceLifeTime
my note about C Sharp ServiceLifeTime