Linux Pipes and Redirects

Chain commands and capture output like a shell native.

  • linux pipe
  • redirect stderr
  • tee
  • pipefail
  • stdout stdin

Linux Pipes and Redirects

Chain commands and capture output like a shell native.

Commands

CommandWhat it does
stdout plus stderr to fileMerge streams with 2-and-1
append redirectAppend instead of overwrite
pipe commandsFeed stdout into the next command
tee save and showSee output AND save it
feed file as stdinRedirect a file into a command

Example

./deploy.sh 2>&1 | tee deploy.log
grep ERROR deploy.log | head

FAQ

Does redirect order matter?

Yes - the stream merge must come last, or stderr goes to the old terminal.

Do pipelines hide failures?

Pipelines return the last command's code - set pipefail in scripts to catch mid-pipe failures.

常见问题

Does redirect order matter?
Yes - the stream merge must come last, or stderr goes to the old terminal.
Do pipelines hide failures?
Pipelines return the last command's code - set pipefail in scripts to catch mid-pipe failures.

Linux