How to save cron job output to file?

Better Stack Team
Updated on January 9, 2023

Any cron job can generate output. It may be log or error messages. Regardless of the nature of the output, you may want to save this output to a file. This can be done using the > operator.

Saving cron job output to file

To save the output from the cron job running the shell script to a file, use the following command:

*   *  *   *   *   /bin/ > /bin/file.txt 2>&1

Let's break down this cron job:

  • /bin/ > /bin/file.txt states that the output from /bin/ will be redirected and saved in the /bin/file.txt
  • 2>&1 states that the standard error (2>) is redirected to the same file descriptor that is pointed by standard output (&1)
Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack