Jump to content

Redirection

From Squishu Wiki

General

  • 0 = stdin
  • 1 = stdout
  • 2 = stderr
  • Each of these can be redirected independently
  • To redirect stderr, preface the > with the number of the file descriptor to redirect> This is often used to discard error info from appearing on the screen
    • since stderr is on file descriptor 2, use 2>
  • Redirect stdout and stderr to different files
    • kill iHUP 1234 >killout.txt 2>killerr.txt
    • I am guessing that 1 is the default so you don't see 1>
  • Redirect stdout and stderr to the same file
    • kill -1 1234 >blah.txt 2>&1
      • Read it like this: redirect stdout to the file blah.txt, then direct stderr to the same place as stdout
  • Redirect all output, stdout and stderr, to /dev/null
    • kill -1 1234 >/dev/null 2>&1
  • Redirecting input is kind of lame
    • more < blah.txt
      • why not just do more blah.txt