Saving output to files · บันทึกเอาต์พุตลงในไฟล์
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · หน้านี้ต้องใช้เบราว์เซอร์ล่าสุด (รองรับ SharedArrayBuffer) กรุณาอัปเดต Chrome, Edge, Firefox หรือ Safari เป็นเวอร์ชันล่าสุด
English
Catching the output
- Normally a command's output appears on screen. The
>symbol redirects it into a file instead:
- Nothing prints — the text went into
greeting.txt. Read it back withcat greeting.txt.
ไทย
การจับผลลัพธ์
- ปกติแล้วผลลัพธ์ของคำสั่งจะปรากฏบนหน้าจอสัญลักษณ์
>** redirect** ผลลัพธ์นั้นเข้าไปในไฟล์แทน:
echo hello > greeting.txt
- ไม่มีอะไรถูกพิมพ์ — ข้อความถูกส่งเข้า
greeting.txtแล้ว อ่านกลับออกมาได้โดยใช้cat greeting.txt
English
Replace vs add
>replaces the file's contents (or creates it if new).>>appends — it adds to the end, keeping what was there:
- Use
>>when you are building up a file, like a log.
ไทย
แทนที่ vs เพิ่ม
>แทนที่ เนื้อหาของไฟล์ (หรือสร้างใหม่หากเป็นไฟล์ใหม่)>>เพิ่มต่อ —它会เพิ่ม vào cuối, รักษาสิ่งที่มีอยู่แล้วไว้:
echo line one > notes.txt
echo line two >> notes.txt
- ใช้
>>เมื่อคุณกำลังสร้างไฟล์ เช่น ไฟล์บันทึก (log)
English
Why this matters
- Saving output lets you keep results, build files from commands, and feed one program's output to another.
- ⚠️ Watch out:
>on an existing file erases it first. Use>>when you mean "add".
ไทย
ทำไมสิ่งนี้จึงสำคัญ
- การบันทึกผลลัพธ์ช่วยให้คุณเก็บผลที่ได้ สร้างไฟล์จากคำสั่ง และส่งผลลัพธ์ของโปรแกรมหนึ่งไปยังอีกโปรแกรมหนึ่งได้
- ⚠️ ระวัง:
>กับไฟล์ที่มีอยู่เดิม จะลบไฟล์ออกก่อน ให้ใช้>>เมื่อต้องการคำว่า "เพิ่ม"
English
Common mistakes
>overwrites a file;>>adds to the end.>on a file that already exists erases it first.
ไทย
ข้อผิดพลาดที่พบบ่อย
>จะเขียนทับไฟล์;>>จะเพิ่ม vào cuối>กับไฟล์ที่มีอยู่เดิมจะลบไฟล์ออกก่อน
Send the output of echo into a file with >. Write hello into greeting.txt, then cat it back. · ส่งเอาต์พุตของ echo เข้าไฟล์ด้วย > เขียน hello ลงใน greeting.txt, จากนั้น cat มันกลับมา
>> adds a line instead of replacing. Write first into log.txt, then append second, then show the file. · >> เพิ่ม บรรทัดแทนที่จะแทนที่ เขียน first ลงใน log.txt, จากนั้น append second, แล้วแสดงไฟล์