I know how to redirect the output of a terminal to a file. For example, if I want to list all the files in ~/Documents and output to a file called test.txt, I would do this:
ls ~/Documents > test.txt
The question is, can I copy the output to test.txt AFTER I have carried out the command? This would mean that I wouldn't have to know in advance whether I want to copy the output to file. I want to do something like this:
<bash command for copying standard output to test.txt>
Any help will be appreciated thanks.