9

On linux at least, and I think windows/dos shell too you can use > to "pipe" output into a file. Something like:

cat myfile.txt > mightAsWellCP.txt

What is that piece of syntax sugar called? This is a "pipe": | so what do we call the > and < (and << and >> while were at it.)

  • 2
    Redirect maybe? – Brian Adkins Sep 28 '12 at 0:50
  • @BrianAdkins write this up as an answer – soandos Sep 28 '12 at 0:58
  • "Piping" refers to using the output of one program as the input of another. > doesn't pipe output; it redirects it. As for what the symbols are called, I usually call them "less-than" and "greater-than", even though that's not how they're being used. (Or in print, I just call them < and >.) – Keith Thompson Sep 28 '12 at 1:02
  • @BrianAdkins is correct - see en.wikipedia.org/wiki/Redirection_(computing) – Kelvin Sep 28 '12 at 1:08
9

I usually refer to all four variations (< << > >>) as a "redirect" when speaking to folks that I know will understand.

| improve this answer | |
5

They're symbols for redirection of input/output.
Quick runthrough on the differences between the redirection syntax commands

| improve this answer | |
5

> is used to redirect output.

$echo "hello" > file.txt

< is used to redirect input.

$ cat < file.txt

Output:

hello

>> is used to append output to the end of the file.

$ echo "world!" >> file.txt

Output:

hello
world!

<< (called here document) is a file literal or input stream literal.

$cat << EOF >> file.txt

Output:

>

Here you can type whatever you want and it can be multiline. It ends when you type EOF (We used EOF in our example but you can use something else instead).

> linux
> is
> EOF

Output:

hello
world!
linux
is

<<< (called here string) is the same as << but takes only one word.

$cat <<< great! >> file.txt

Output:

hello
world!
linux
is
great!

Note that we could have used $cat <<< great! | tee file.txt instead of $cat <<< great! >> file.txt.

| improve this answer | |
3

When speaking a command-line, I usually pronounce the symbols by their function.

  • > "output to"
  • >> "append to"
  • < "input from"
  • | "pipe"

So when reading your example out loud:

cat myfile.txt > mightAsWellCP.txt

I would pronounce as "cat myfile dot T X T output to might as well C P dot T X T".

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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