stdin, stdout and stderr
Redirecting
stdin is a channel where one provides input (keyboard, typically)
stdout is a channel that a script or program uses to output information
stderr is another channel used by a script or program to output errors
< redirect stdin
redirect stdout
2> redirect stderr
Examples:
This redirects any errors to the ‘err’ file
ls nonexistentfile 2> err
This redirects any actual output to the ‘out’ file and errors to ‘err’
ls nonexistentfile 2> err > out
This redirects stderr to stdout and then both to the file:
ls nonexistentfile > file.txt 2>&1
Though I don’t yet understand why it is that it needs to happen in that particular order. I would’ve assumed 2>&1 > file.txt but it doesn’t work that way.