Linux Input Output Redirection Explained

By Manish

Published on:

Follow Us
Linux Input Output Redirection

Linux system में काम करते समय हम अक्सर data को एक जगह से दूसरी जगह भेजने की आवश्यकता महसूस करते हैं। Input-Output Redirection एक powerful feature है जो हमें commands के output और input को control करने की सुविधा देता है। आइये, RHCSA EX200 exam के perspective से इसके बारे में विस्तार से जानते हैं।

Standard Input, Output, and Error

Linux में तीन main data streams होते हैं:

  • Standard Input (stdin): Default input device, usually keyboard (File descriptor 0)
  • Standard Output (stdout): Default output device, usually terminal screen (File descriptor 1)
  • Standard Error (stderr): Error messages output device, usually terminal screen (File descriptor 2)

Redirection Operators

1. Output Redirection (> and >>)

>: यह operator existing file के content को overwrite कर देता है।

$ echo "Hello World" > file.txt

>>: यह operator existing file में content को append कर देता है।

$ echo "Hello Again" >> file.txt

2. Input Redirection (<)

<: यह operator command के input को file से लेता है।

$ wc -l < file.txt

3. Pipe (|)

|: यह operator एक command के output को दूसरे command के input के रूप में use करता है।

$ ls -l | grep "myfile"

4. Error Redirection (2> and 2>>)

2>: यह operator error messages को redirect करता है, existing file को overwrite करते हुए।

$ ls non_existing_file 2> error.log

2>>: यह operator error messages को redirect करता है, existing file में append करते हुए।

$ ls another_non_existing_file 2>> error.log

5. Combine Output and Error (&> and &>>)

&>: यह operator standard output और error दोनों को redirect करता है।

$ ls file1 file2 non_existing_file &> output.log

&>>: यह operator standard output और error दोनों को append करता है।

$ ls file1 file2 another_non_existing_file &>> output.log

Practical Examples

1. Redirecting Output to a File:

$ echo "This is a test" > testfile.txt

2. Appending Output to a File:

$ echo "This is an additional line" >> testfile.txt

3. Using Pipe for Filtering:

$ ps aux | grep "httpd"

4. Redirecting Errors:

$ ls non_existing_file 2> errors.txt

5. Combining Output and Error:

$ ls file1 file2 non_existing_file &> all_output.log

Conclusion

Input-Output Redirection Linux system में बहुत महत्वपूर्ण है, विशेष रूप से RHCSA EX200 exam की तैयारी के लिए। यह feature हमें commands के output और errors को manage करने में मदद करता है। ऊपर दिए गए examples और commands को practice करके आप अपनी skills को और भी निखार सकते हैं।

Author

Manish

मैं एक हिंदी वेबसाइट कंटेंट राइटर हूं जिसके पास विभिन्न श्रेणियों में आकर्षक लेख लिखने का 3 साल का अनुभव है साथ ही मुझे English कंटेंट राइटर का भी अनुभव है

Leave a Comment