How can Linux redirect command output to a file?

To save the output of Linux commands to a file, you can use the redirect symbol ” > “. Here are some examples:

  1. Redirect the standard output of the command to a file.
command > output.txt
  1. Direct both the standard output and standard error of the command to a file.
command > output.txt 2>&1
  1. Append the standard output of the command to the end of the file.
command >> output.txt
  1. Append both standard output and standard error output of the command to the end of the file.
command >> output.txt 2>&1

Please note, in the above example, “command” refers to the Linux command to be executed, and “output.txt” is the filename to output to. Feel free to replace the commands in these examples with the ones you want to execute.

bannerAds