الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

tee

Copy the input to the screen (or the next command) and to one or more files at the same time.

المستوى
لينكس اليومي
المجموعة
النصوص والبحث
يحتاج root
لا
الحزمة
coreutils

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

tee sits in a pipe like a T-piece in a water pipe: data goes through, and a copy goes into files. You see the output and keep it.

A very common use: write to a file that only root may change, from a normal user, with echo ... | sudo tee FILE. The redirect > would run as your user and fail; tee runs with sudo.

طريقة الكتابة

tee [OPTION]... [FILE]...

الخيارات 6

الأكثر استخدامًا

-a, --append
Add to the end of the files instead of overwriting them.
-i, --ignore-interrupts
Ignore Ctrl+C (the interrupt signal).
-p
Report errors when writing to pipes (and go on with other outputs).
--output-error[=MODE]
What to do when a write fails: warn, warn-nopipe, exit, exit-nopipe.
--help
Show help.
--version
Show the version.

أمثلة 11

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1See the output and save it

    dnf check-update | tee updates.txt

    You watch the list and keep a copy for your change ticket.

  2. 2Write a root-owned file from a normal user

    echo "net.ipv4.ip_forward = 1" | sudo tee /etc/sysctl.d/90-forward.conf

    sudo echo ... > file fails because the redirect is not done by sudo.

  3. 3Add a line to a root-owned file

    echo "192.168.122.20 server2" | sudo tee -a /etc/hosts

    -a appends. Without it the file would be replaced.

  4. 4Hide tee's copy on the screen

    echo "export EDITOR=vim" | sudo tee /etc/profile.d/editor.sh > /dev/null

    Only the file gets the text.

  5. 5Write several files at once

    ip -br a | tee /tmp/net-$(hostname).txt /srv/reports/net-latest.txt

    One command, two copies.

  6. 6Log a long script and still watch it

    ./upgrade.sh 2>&1 | tee -a /var/tmp/upgrade-$(date +%F).log

    2>&1 sends errors into the pipe too, so the log is complete.

  7. 7Save the middle of a pipe

    journalctl -u sshd --since today | tee ssh-today.log | grep -c "Failed password"

    The full log is saved; the screen shows only the count of failed logins.

  8. 8Write a heredoc to a protected file

    sudo tee /etc/yum.repos.d/local.repo > /dev/null <<'EOF'
    [local-baseos]
    name=Local BaseOS
    baseurl=file:///repo/BaseOS
    gpgcheck=0
    EOF

    A clean way to create config files in scripts that run as a normal user with sudo.

  9. 9Keep running when you press Ctrl+C

    ping server2 | tee -i ping.log

    With -i, tee is not stopped by Ctrl+C, so the log gets the last lines.

  10. 10Record a kubectl apply for the change log

    kubectl apply -f deploy.yaml 2>&1 | tee -a changes.log

    Every change is visible now and stored for later.

  11. 11Count and save matches at the same time

    grep "ERROR" app.log | tee errors.txt | wc -l

    The number on the screen, the lines in the file.

انتبه

  • Without -a, tee overwrites the file.
  • In sudo tee, only tee runs as root; the command before the pipe runs as you.

نصائح للحفظ

  • tee = T-piece: one input, two outputs (screen + file).
  • | sudo tee FILE = write as root. | sudo tee -a FILE = append as root.

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man tee