Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a simple method to dump pipe input to a file? (Linux)

Tags:

linux

pipe

exim

I'm looking for a little shell script that will take anything piped into it, and dump it to a file.. for email debugging purposes. Any ideas?

like image 434
Alex Fort Avatar asked Sep 16 '08 20:09

Alex Fort


People also ask

How do you pipe an output to a file?

the shortcut is Ctrl + Shift + S ; it allows the output to be saved as a text file, or as HTML including colors!

How do you pipe in Linux?

You can make it do so by using the pipe character '|'. Pipe is used to combine two or more commands, and in this, the output of one command acts as input to another command, and this command's output may act as input to the next command and so on.

How do you take input from a file in Linux?

To redirect input from a file, use the less-than symbol (<). The example here uses the sort command which simply sorts the input in order. The shell reads the contents of the required_packages. txt file into the standard input of the sort command which then orders the text and displays it on standard output.

What character is used to pipe data from the output of one program to the input of another?

The pipe character | is used to connect the output from one command to the input of another. > is used to redirect standard output to a file.


4 Answers

The unix command tee does this.

man tee
like image 70
Stephen Deken Avatar answered Oct 21 '22 03:10

Stephen Deken


cat > FILENAME
like image 26
Commodore Jaeger Avatar answered Oct 21 '22 04:10

Commodore Jaeger


You're not alone in needing something similar... in fact, someone wanted that functionality decades ago and developed tee :-)

Of course, you can redirect stdout directly to a file in any shell using the > character:

echo "hello, world!" > the-file.txt
like image 42
Isak Savo Avatar answered Oct 21 '22 04:10

Isak Savo


The standard unix tool tee can do this. It copies input to output, while also logging it to a file.

like image 30
Brian Mitchell Avatar answered Oct 21 '22 03:10

Brian Mitchell