logoalt Hacker News

jasongitoday at 3:09 AM2 repliesview on HN

The beauty of cat is that streams are the universal interface.

Program A might accept a file as the last positional arg. Program B might accept it as a named arg, where the name/flag could be anything from --input or -f or --file etc.

But a program will read from STDIN, which all good unix programs do, then piping cat into it works every time. I can write the cat foo.txt part before I even know what command I'm piping it into.


Replies

fuzzybear3965today at 3:17 AM

This. Sometimes I want to see what I'm looking at and then (using that dump as a reference) follow up with a corresponding filter (| jq .key, or | tail -n 30). Sure, I could use less, but then I context switch on exit; no support from the scrollback buffer.

I've probably lost 10ms * 1E5 of my life from the extra PID. But, probably would lose more in the context switch.

show 2 replies
hn_throwaway_99today at 3:26 AM

Yeah, I read TFA, and my eyes were rolling the whole time. Some people really have a bee in their bonnet that "cat" is named that way because it was originally for concatenating files. Nobody fucking cares. It's the standard way for writing a file to standard out, and the general pattern of "cat file.txt | somecommand | othercommand | anothercommand" is so useful because it follows the pipeline pattern so well - read from standard in, write to standard out - that is the cornerstone of Unix shell commands IMO.

"Oh no, it spawns another process!!" Again, nobody cares.

show 1 reply