A catalogue of bash control and redirection operators for chaining commands and wiring up I/O.
|pipes a stream to a process.<>>>redirect a stream to/from a file. Before typing either, be crystal clear whether the right-hand side is a process or a file — picking the wrong operator is the #1 source of confusion.
ls | out.txt ❌ (out.txt is a file, not a process) → ls > out.txt ✅wc -l > input.txt ❌ (would truncate input.txt) → wc -l < input.txt ✅cat log > grep ERROR ❌ (grep is a process) → cat log | grep ERROR ✅; && ||make ; notify-send done # unconditional sequencing (run next regardless of exit status)sudo apt update && sudo apt upgrade # refresh index first, then upgrade only if it succeeded./program && echo Success # echoes only if program exited 0make || echo "build failed" # fallback message when make returns non-zero| processjournalctl -u nginx | less # paginate output of any commandecho "hello" | tr a-z A-Z # transform text via stdin -> HELLOps aux | grep node # filter another command's outputmake |& less # bash shorthand: pipe both stdout and stderr (compiler errors go to stderr)< > >> 2> &>wc -l < input.txt # feed file as stdin (output is just the number, no filename)printf "line1\nline2\n" > out.txt # write stdout to file (truncates)printf "line1\nline2\n" >> appending.txt # append instead of replacinggcc main.c 2> errors.log # redirect stderr only (stdout still goes to terminal)./render.exe > run.log 2>&1 # send both streams to file; order matters (2>&1 > run.log would NOT work)./render.exe &> run.log # bash shorthand for the line abovecommand -v node &>/dev/null # silence both streams; common "is it installed?" idiom (POSIX: >/dev/null 2>&1)