News for hackers. Stuff that matters.
Re:PSA about abuse of cat(1) command. Don't abuse cats by jasongi on Friday July 17, 2026 @11:09PM (#48954828)
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.

Re:PSA about abuse of cat(1) command. Don't abuse cats by fuzzybear3965 on Friday July 17, 2026 @11:17PM (#48954861)
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.

Re:PSA about abuse of cat(1) command. Don't abuse cats by 1-more on Friday July 17, 2026 @11:36PM (#48954974)
I'm never doing just one thing to a file! I'm grepping and JQing and then piping it to JQ again because I'm kind of dumb (and it's faster to do what I do know how to do than it is to look up the perfect way to do it), then I'm outputting as a TSV and piping that to `column -ts $'\t'`. ^r reveals a decent example:

    cat expected.1376| sed '1,4d' | rg '(\t\d)\t.*' --replace '$1' | column -ts $'\t'
I was figuring shit out along the way and it'd be pretty annoying to adjust which command gets the filename throughout that process.

You know what? I'll tell you another thing I do that's similar:

    SELECT * FROM whatever WHERE true
        AND last_modified > 123
        AND otherfield NOT NULL
Always bugged me that you say WHERE for the first one and AND thereafter, so if I'm poking around the database trying to create actionable insights for key stakeholders at the speed of business just as I was above with the text file, I like to be able to futz and delete/add clauses as I see fit just as I do pipeline stages.
Re:PSA about abuse of cat(1) command. Don't abuse cats by oogali on Friday July 17, 2026 @11:29PM (#48954935)
alias less=‘less -X’
Re:PSA about abuse of cat(1) command. Don't abuse cats by fuzzybear3965 on Saturday July 18, 2026 @06:23AM (#48956695)
Oh nice. Thanks!
Re:PSA about abuse of cat(1) command. Don't abuse cats by hn_throwaway_99 on Friday July 17, 2026 @11:26PM (#48954921)
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.

Re:PSA about abuse of cat(1) command. Don't abuse cats by adrian_b on Saturday July 18, 2026 @12:37AM (#48955266)
The simpler and better way to write your pipeline is:

"< file.txt somecommand | othercommand | anothercommand"

There is never any need for "cat".

When such a pipeline is used repeatedly in a script, the time for executing the redundant process "cat" can easily add up to a noticeable delay.

Re:PSA about abuse of cat(1) command. Don't abuse cats by mcphage on Saturday July 18, 2026 @09:25AM (#48957970)
That’s neither simpler, nor better.

> "cat" can easily add up to a noticeable delay.

If you have a slow script, you will have more useful places to optimize than removing calls to cat.

Re:PSA about abuse of cat(1) command. Don't abuse cats by adrian_b on Saturday July 18, 2026 @12:32AM (#48955237)
Yes, but "cat" is superfluous anyway.

You can start your pipeline with a file redirection: " <input_file prog1 | prog2 | prog3 | ... | progN >output_file".

Re:PSA about abuse of cat(1) command. Don't abuse cats by xboxnolifes on Saturday July 18, 2026 @06:52PM (#48963274)
My pipeline starts with displaying the file to stdout to make sure it's the correct file, and then building on from there, one new program call at a time. This is not a valid alternative.