Redirect all output to file and run in background

Reading Time: 1 minute


$ command-to-run arguments > output_file 2>&1 &


  • > is used to redirect the command’s (command-to-run) output to the output file (output_file) and replace the file’s current content. If you want to append to the file’s current content you can use the >> operator instead.
  • 2>&1 – redirects stderr to “where stdout is currently going”. In our case that is output_file. In other words the &1 reuses the file descriptor that stdout is currently using.
  • & tells our command to run in the background.

We transform challenges into digital experiences

Get in touch to let us know what you’re looking for. Our policy includes 14 days risk-free!

Free project consultation