<>

Pipes, standard output and standard input

December 26, 2009

In linux, standard input refers to the stream of bits that come from your keyboard.

Standard output refers to the stream of bits that appear on your screen(terminal).

You can change this around so that standard input comes from another source(say, a file) or so that standard output gets directed somewhere else (say, a file).

For example, say we wanted to email someone a file containing the contents of our home directory. We could do this:

ls ~ | vim -

This will pipe the output from the ls command to vim. You can then edit and save this file normally as you would in vim.

There's another type of pipe you could use for this example: greater than.

ls ~ > contents.txt

This will redirect the output to the contents.txt file.

You can also append output by using two greater than signs:

ls ~ >> some_file.txt

As you would expect, the less than sign can be used to direct a file as standard in.

Notes




Built with Scroll v161.0.0