Shell Tip: tee

החלטתי לפתוח מדור טיפים לשורת הפקודה של לינוקס (ולא רק).
המטרה: לתת במה למספר פקודות פשוטות ויעילות שלא בהכרח מוכרות לכולם.
הערה: ההסברים לקוחים מהפאלם האישי ולכן כתובים באנגלית

tee

redirections are great tools for sending command output (stdout) to a file (other than the screen).  pipe make the output of one command as input of other command

But if you want, in a single command, to do two things:
display the command output on the screen and write it to a file. In this case you  should use the tee command

Examples:
ls | tee ls.txt
ls | tee -a ls.txt

the -a option will append the file (default is overwrite)

These commands will display the contents of the current directory on the screen, and write the same information to ls.txt file

My Signature
This entry was posted in טיפים לשורת הפקודה, לינוקס ותוכנה חופשית. Bookmark the permalink.

2 Responses to Shell Tip: tee

  1. ליאור קפלן says:

    מומלץ להפנות את פלט השגיאות לפלט הרגיל לפני tee וזאת כדי שכל המידע יכתב לקובץ. אחרת המידע על השגיאות הולך לאיבוד, ובסקריפטים הוא בד"כ חשוב.

    חוץ מזה, זה אחלה כלי.

  2. ilanshavit says:

    קיבלתי. כלומר לבצע:
    ls 2>stdout |tee ls.txt

כתיבת תגובה

האימייל שלך לא יוצג באתר. (*) שדות חובה מסומנים

*

תגי HTML מותרים: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>