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.

2 Answers 2

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.

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

3
  • Is there a way to copy and paste from the xterm window without using the mouse? That's basically what I'm trying to do.
    – Eddy
    Oct 26, 2010 at 13:13
  • none that I'm aware of ... :(
    – kdo
    Oct 26, 2010 at 13:14
  • If you're in a shell session within Emacs, you can copy/paste without using a mouse. Oct 26, 2010 at 13:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .