Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 0 down vote accepted

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.

share|improve this answer

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

share|improve this answer
    
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 '10 at 13:13
    
none that I'm aware of ... :( –  kdo Oct 26 '10 at 13:14
    
If you're in a shell session within Emacs, you can copy/paste without using a mouse. –  Doug Harris Oct 26 '10 at 13:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.