Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Linux if you type

sort < txtfile

is that the same thing as

cat txtfile | sort
share|improve this question
up vote 13 down vote accepted

To your title question: No. Getting stdin from file contents (input redirection) is not the same as piping one program's output to another program's input.

But, as your cat actually just prints a file's contents, the result is effectively the same in that example.

But even just the following produce very different results:

$ cat * | sort
$ sort < *

If there's more than one matching file, the latter will produce

-bash: *: ambiguous redirect

since it's just not as flexible as the former, which will cat all matching files, and pipe them as input into sort.

share|improve this answer
What about... sort *? No useless use of cat, no useless use of indirection, shortest to type, easiest to think of, and I believe GNU sort will treat you to scalability optimizations for very large files (not so sure about that - half remembering something there) – sehe Oct 25 '12 at 23:05
@sehe Probably. I just used the example to show the two are different. This isn't about efficient use of sort. Sort is more flexible thn that though, sure. – Daniel Beck Oct 26 '12 at 4:11
@DanielBeck, Regarding efficiency, is sort < txtfile much more efficient than cat txtfile | sort? – Pacerier Mar 13 '15 at 11:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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