stdout vs stderr: the basics
A simple command likels writes its normal results to standard output (stdout). Flags change the format or content of stdout; for example ls -l prints a detailed listing:
ls -j), the program prints an error message to standard error (stderr):

mv moves or renames files without printing anything to stdout unless you request verbose output:
mv cannot find the source file, it writes an error to stderr:
Redirection refresher
By default> (greater-than) and >> (append) redirect only stdout. That means error messages sent to stderr are not captured by > unless you explicitly redirect stderr.

echo and file redirection:
>:
2>? Unix-like processes use numeric file descriptors for standard streams:
0— standard input (stdin)1— standard output (stdout)2— standard error (stderr)
1> redirects stdout; 2> redirects stderr.
Examples showing separate files for stdout and stderr:
Merging streams: redirect stderr into stdout (and ordering)
You can send stderr to wherever stdout is currently going by using2>&1. Similarly, you can redirect stdout to wherever stderr is going with 1>&2.
Important: the order of redirections matters. Typically you redirect stdout first, then point stderr at stdout:
2>&1 > all.txt) the shell first redirects stderr to the current stdout (usually the terminal) and then redirects stdout to all.txt, leaving stderr still connected to the terminal.
When you want stderr to end up in the same place as stdout, use the pattern:
command >file 2>&1. Always redirect stdout first, then redirect stderr to 1.Quick operator reference
Quick text summary:
Wrap-up
You now know:- stdout and stderr are separate streams (fd 1 and fd 2).
>and>>affect stdout by default.- Use
2>to capture stderr, and2>&1to merge stderr into stdout (remember ordering). - Properly separating or merging streams helps with debugging and script reliability.
Links and references
- Shell Scripts for Beginners
- GNU Bash manual: Redirections — https://www.gnu.org/software/bash/manual/html_node/Redirections.html