SkillByAIइंटरैक्टिव संस्करण खोलें →

पाठ 22 / 31

रीडायरेक्शन

Output सहेजने या चुप करने के लिए >, >>, 2> और /dev/null से stdout, stderr व stdin redirect करें।

दो आउटपुट स्ट्रीम

हर प्रोसेस में stdout (सामान्य आउटपुट) और stderr (एरर आउटपुट) होता है, साथ ही इनपुट के लिए stdin। रीडायरेक्शन से आप इन्हें स्क्रीन की बजाय फाइलों में भेज सकते हैं।

>, >> और 2>

> फाइल को stdout से ओवरराइट करता है, >> जोड़ता है, 2> stderr को अलग से capture करता है।

ls /etc > listing.txt        # overwrite
ls /etc >> listing.txt       # append
ls /nope 2> errors.txt       # stderr only

Output:

cat errors.txt
# ls: cannot access '/nope': No such file or directory

आउटपुट फेंक दें

/dev/null एक ब्लैक होल है — अवांछित आउटपुट वहाँ भेजें: command > /dev/null 2>&1 सब कुछ शांत कर देता है।