How to: Export output from Terminal to a text file in macOS or Windows


Instructions

  1. Open Terminal by following the directions linked below for your operating system:

  2. Type your chosen command. After the command, type a space, the greater than symbol (>), and another space. Then, type the name for the file that you wish to generate. Lastly, type a space and then 2>&1. Press Enter/return to submit the command.

    EXAMPLE:

    ping www.ttu.edu > filename.txt 2>&1

    Here is an example screenshot from Windows:

    Terminal in Windows 11 showing a sample command typed

    Here is an example screenshot from macOS:

    Terminal in macOS Tahoe showing a sample command typed

Outcome

The results of the command are exported to the file you specified. Unless you specified a file path, the file is saved in the root of your user profile folder. This is true for both macOS and Windows, even if the command was run with administrative privileges.

File Explorer in Windows 11 showing an example text file in the user's home folder

Finder in macOS Tahoe showing an example text file in the user's home folder

TIP: To control where the file is saved, you can alter the command to include the path on your computer where you wish to save the file.

TIP: If there is a space in the file path or file name in Windows, just surround the entire path and file name in quotation marks.

EXAMPLE:

ping www.ttu.edu > "c:\users\jdoe\desktop\ping results.txt" 2>&1

Terminal in Windows 11 showing a sample command typed

TIP: If there is a space in the file path or file name in macOS, place a backslash in front of the space.

EXAMPLE:

ping -c 10 www.ttu.edu > /Users/jdoe/Desktop/ping\ results.txt 2>&1

Terminal in macOS Tahoe showing a sample command typed