Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinhooke/7c865d6f5c7e70b4f07af3948ae441ef to your computer and use it in GitHub Desktop.
Save kevinhooke/7c865d6f5c7e70b4f07af3948ae441ef to your computer and use it in GitHub Desktop.
stdin, stdout, stderr and redirection
0 = stdin
1 = stdout
2 = stderr
#redirects stdout from command to file
command > file
#equivalent to
command 1> file
#if command writes errors to stderr, redirecting only stdout doesn't capture the errors
#this redirects stderr to errors.txt, stdout is left unchanged
command 2> errors.txt
#redirects stdout from command to file and then redirects stderr to current redirection for stdout (also to the file)
#note that this order is important
command > file 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment