4

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:

ls ~/Documents

Then this:

<bash command for copying standard output to test.txt>

Any help will be appreciated thanks.

Eddy
  • 3,427

2 Answers2

1

you could start your shell session in an Emacs window and then simply copy and paste

(you could also issue a command from within vi and assemble the output in the current vi buffer),

or you could copy and paste from your xterm window,

or you could run your shell session using script(1), and later edit the session output,

or you could simply redo your command.

I hope this helps, Klaus

kdo
  • 387
0

You could use tee, but that's not strictly after you ran the previous command.

ls ~/Documents | tee test.txt

Will write the output to your command line session normally and also write it to test.txt.

Alternately, if you're running within GNU screen, there are commands to move around in the scrollback buffer and copy/paste. More info in this superuser question.

Doug Harris
  • 28,397