/dev/null का उपयोग
/dev/null एक magic trash chute जैसा है जो आप जो भी इसमें डालें उसे बिना कोई trace छोड़े निगल जाता है। आप noisy messages वहां भेजते हैं जब आप उन्हें देखना नहीं चाहते।
In this page:
Syntax
command > /dev/null
command 2> /dev/null
/dev/null
/dev/null एक special file है जो इसमें लिखी गई किसी भी चीज़ को discard कर देता है, आमतौर पर उस output को silence करने के लिए उपयोग किया जाता है जिसकी आपको परवाह नहीं। दोनों streams को वहां redirect करना, command > /dev/null 2>&1, सारे output को पूरी तरह suppress कर देता है।
/dev/null से पढ़ना हमेशा तुरंत बिना किसी data के end-of-file return करता है।
Note:
command > /dev/null 2>&1 "इसे चलाएं और इसका सारा output छुपाएं" के लिए standard idiom है।उदाहरण: /dev/null
#!/bin/bash
echo "This will be discarded" > /dev/null
echo "This still prints normally"
ls /no/such/path > /dev/null 2>&1
echo "The error above was silenced. Exit code: $?"
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
> /dev/nullसे redirect करना और फिर भी errors देखना, क्योंकि आपको2>&1या2> /dev/nullभी चाहिए।2>&1 > /dev/nullको गलत order में लिखना, इसलिए errors अब भी terminal पर दिखती हैं।- एक command का सारा output छुपाना और फिर यह पता न कर पाना कि यह fail क्यों होता है।
🔒
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first: