Bash stderr (Standard Error)
stderr (standard error, file descriptor 2) is a separate output stream for error messages.
Redirect it with 2>. Use 2>&1 to send it to the same place as stdout, and >&2 to write your own message to stderr.
Save errors to a file
ls missing.txt 2> errors.txt
cat errors.txt
ls: cannot access 'missing.txt': No such file or directory
Output and errors in one file
ls notes.txt missing.txt > all.txt 2>&1
cat all.txt
ls: cannot access 'missing.txt': No such file or directory
notes.txt