Skip to content

Linux tee Guide

Mattscreative edited this page Nov 20, 2025 · 2 revisions

📋 Linux tee Guide

Complete beginner-friendly guide to tee on Linux, covering Arch Linux, CachyOS, and other distributions including duplicating output, logging, and output redirection.


📋 Table of Contents

  1. Understanding tee
  2. tee Basics
  3. Output Duplication
  4. Logging
  5. Troubleshooting

🎯 Understanding tee

What is tee?

tee duplicates output to files and stdout.

Uses:

  • Duplicate output: Send to file and screen
  • Logging: Save output while viewing
  • Pipeline tool: Split output streams
  • Debugging: Save output for analysis

Why it matters:

  • Logging: Save output while viewing
  • Debugging: Capture output
  • Monitoring: Watch and log simultaneously

📋 tee Basics

Basic Usage

Simple example:

# Save to file and display
ls -l | tee output.txt

# Shows on screen and saves to file

Append Mode

Append to file:

# Append mode
ls -l | tee -a output.txt

# -a = append (doesn't overwrite)

📄 Output Duplication

Multiple Files

Save to multiple:

# Multiple files
ls -l | tee file1.txt file2.txt

# Saves to both files

With sudo

Save with sudo:

# Save to protected file
ls -l | sudo tee /root/output.txt

# tee needs sudo, not ls

📝 Logging

Command Logging

Log commands:

# Log command output
command | tee log.txt

# View and save

Script Logging

In scripts:

#!/bin/bash
{
    echo "Starting script"
    # commands here
} | tee script.log

🔧 Troubleshooting

tee Not Found

Check installation:

# Check tee
which tee

# Usually in coreutils
# Install if missing
sudo pacman -S coreutils

📝 Summary

This guide covered tee usage, output duplication, and logging for Arch Linux, CachyOS, and other distributions.


🔗 Next Steps


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.

Clone this wiki locally