Discussion Locked

Redirecting The Outp Put to a text file?

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi All

How can I redirect Output of any Linux Command to the file?..

Thanx
pady

7 replies

by michael2

command > file.txt
command >> file.txt

A single gt sign will create a new file with the name of the file you specify. If that file exists it will be overwrittin. If you use double gt signs the output of the command will be appended to the file of that name. If the file name doesn;t exist it will be created.

by achuprinin

It depends on what do you want:
- if you want redirect ONLY standart output use redirection sign '>' (greater) to create new file for output or put it twice to add to the end of existing file. Ex.:
command > newfile
command >> existingfile
- if you want redirect both standart output and error output add '2>&1' at the end of command line. Ex.:
command args > newfile 2>&1
command args >> existingfile 2>&1
- if you want redirect full output to file but also to see what command sends to output use `tee' filter. Ex.:
command args 2>&1 |tee newfile
command args | tee -a existingfile

This discussion is closed to new replies.