Stop running commands blind, log and watch at the same time
Shell Scripting / Bash Tricks
Stop running commands blind, log and watch at the same time
🧩 The Challenge
Ever kick off a long process, but you *really* need to see the output scrolling by? And then you realize you also want that output saved to a file for later review? You’ve probably run it once to screen, then again redirected to a file, or tried some clunky `script` command dance. What a waste of time.
💡 The Fix
There’s this simple command that lets you do both: pipe your output to `tee`. It’ll print everything to your terminal AND dump it into a file, all in one go. Saves you from rerunning stuff or getting lost in temporary files.
# Run a command, see its output, and save it to a file
my_long_running_command --verbose | tee my_output.log
# Append to the log file instead of overwriting
my_other_command | tee -a my_output.log
# Log both stdout and stderr (bash specific)
my_noisy_command &> >(tee my_noisy_output.log)
⚙️ Why It Works
The `tee` command gets its name because it works like a T-splitter in plumbing, sending its standard input to both standard output and to one or more files. Using `tee -a` tells it to append to the log file instead of overwriting, which is handy. For capturing both stdout and stderr, we’re sending both streams (`&>`) into a process substitution `>(…)` where `tee` then handles the combined output.
🚀 Pro-Tip: Pair this with `pv` for a progress bar on really big files before `tee` if you’re feeling fancy.
Linux Tips & Tricks | © ngelinux.com | 9/24/2026
