How do I create a new file with text outputted from a command?

1

I just want to create a file with the outputted text from a command, rather then copying and pasting & making a new file by hand.

I'm on a unix machine - how do I do this?

ThomasReggi

Posted 2013-01-04T19:04:35.973

Reputation: 443

Answers

6

Redirecting. At the end of any command, type > filename.txt. Replace filename.txt with the file name you want to use. You can even output to different devices (dangerous) or directories (ls > /home/user/ls.txt for example)

As @Josh pointed out as well:

If you need to see the output too you can use the tee command to output to stdout as well as a file. ls | tee file.txt

Canadian Luke

Posted 2013-01-04T19:04:35.973

Reputation: 22 162

2If you need to see the output too you can use the tee command to output to stdout as well as a file. ls | tee file.txt – Josh – 2013-01-04T19:19:59.073

2Plus to append an existing file, use >>. – Xyon – 2013-01-04T21:06:17.737