How to Append Output and Error in Linux

Learn how to Append Output and Error in Linux using the tee command. This is a useful technique for logging and debugging your scripts and applications.

  1. Run the following find command, saving standard output to a file> View the contents of the newly created file:
    $find /etc -name passwd > /tmp/find.out

    $cat /tmp/find.out
  2. Run another find command, saving standard output to the same file.
    $find /etc -name network > /tmp/find.out
    $cat /tmp/find.out
  3. Note the the find command, above, overwrote the original find command output. Now, rerun the two find commands, appending the information. View the results:

    $rm /tmp/find.out
    $find /etc -name passwd > /tmp/find.out
    $find /etc -name group >> /tmp/find.out
    $cat /tmp/find.out
  4. Let’s repeat that command series, but this time, let’s throw away the error messages:
    $rm /tmp/find.out
    $find /etc -name passwd > /tmp/find.out 2> /dev/null
    $find /etc -name squid >> /tmp/find.out 2>/dev/null
    $cat /tmp/find.out

Leave a Comment