I understand what the "cat" command does. I.e.

cat file1 file2 > file3

Will put the contents of file1 and file2 in file3. (If I am not mistaken)

But what exactly does:

cat file1 | file2 > file3


I don't have a UNIX machine to test this on, and I can't google " | ", hence my question.

  • 2
    Nothing... unless file2 is an executable in your path you'll get "command not found: file2" and an empty file3. – don_crissti Mar 4 '16 at 14:42
  • cat has nothing to do with that... unless file2 is an executable it throws an error saying not found. Remove this question or get an online linux shell and test. – Thushi Mar 4 '16 at 14:44
  • @don_crissti And if file2 is an executable? – Pkarls Mar 4 '16 at 14:48
  • @Pkarls if file2 is executable it will get the output of cat file1 as it's stdin and then anything file2 prints to stdout will be put in file3 – Eric Renouf Mar 4 '16 at 14:52
  • After closer investigation, I think that it might be, thanks! – Pkarls Mar 4 '16 at 14:52

It's a pipeline. It will redirect the standard output of the first command into the standard input of the second command.

cat file1 | grep example

For example, the above command will catenate the requested file into grep's stdin.

The command you posted would fail.

cat file1 | file2 > file3

file2 isn't an executable and thus the operation would stop there.

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.