375
Linux Cat (thelemmy.club)

ahh

~$ which cat
you are viewing a single comment's thread
view the rest of the comments
[-] dan@upvote.au 76 points 1 day ago* (last edited 1 day ago)

cat is misunderstood a lot. The purpose of cat is to combine multiple files together (it's literally short for "concatenate"), like cat *.log to combine all log files together.

If you're just using it for a single file, then you should just redirect the file to stdin. These two command lines behave similarly:

cat foo.txt | some-command
some-command < foo.txt

For head, tail, grep and some other commands, you can just pass in the file name directly as an argument (e.g. grep whatever foo.txt).

[-] pedz@lemmy.ca 69 points 1 day ago
[-] shark_byte@lemmy.zip 17 points 1 day ago

awww what's a cat without a head and a tail?

[-] ranzispa@mander.xyz 10 points 23 hours ago

I guess depending on your interpretation of without it could either be "cat" or "a".

[-] ranzispa@mander.xyz 10 points 23 hours ago

Fair, but in general I find it way more useful to use cat for piping.

In most cases I'll do something like

cat file | program
cat file | program | grep
cat file | program | grep | cut

This gets more complicated if the file is at the end of the command.

[-] dan@upvote.au 8 points 23 hours ago

It wouldn't be at the end, since you'd still be piping into program

program <file | grep | cut
[-] jxk@sh.itjust.works 13 points 23 hours ago

And <file program | grep | cut works too

[-] ranzispa@mander.xyz 3 points 22 hours ago

Oh, thanks! Didn't know that

[-] dan@upvote.au 1 points 19 hours ago

Thanks - I didn't know this either!

[-] qqq@lemmy.world 13 points 1 day ago

You'll see cat FILE | all the time because it's just a natural start to a pipeline. You cat FILE to see the content unfiltered before filtering it with further commands.

it’s just a natural start to a pipeline

[-] eager_eagle@lemmy.world 9 points 1 day ago

I still like doing cat file.txt | grep thing because I often re-run it to find something else like cat file.txt | grep thing2 - and if I do that with grep, the pattern sits awkwardly in the middle instead of at the end

[-] tgt@programming.dev 9 points 1 day ago

< file.txt grep thing also works.

[-] sqw@lemmy.sdf.org 1 points 9 hours ago

is it more obtuse

[-] lokalhorst@feddit.org 15 points 1 day ago* (last edited 1 day ago)

If I just want to look at the file, is there a better way than cat foo.txt? I guess I can't just do < foo.txt

[-] dan@upvote.au 11 points 23 hours ago* (last edited 15 hours ago)

Admittedly I still use cat for this.

This also works too, but it's more verbose:

echo "$(<foo.txt)"

It's mentioned in the Bash man pages:

The command substitution $(cat file) can be replaced by the equivalent but faster $(< file).

EDIT: I was just informed that simply <foo.txt works too.

[-] not_IO@lemmy.blahaj.zone 4 points 16 hours ago

how in the world is this not a useless use of echo and equivalent to <foo.txt

[-] dan@upvote.au 4 points 15 hours ago

OK, TIL you can just do <foo.txt. I didn't think that worked. Thanks!

[-] mote@lemmy.ca 19 points 1 day ago

So close! you have to do cat < foo.txt :-) (/s)

[-] TwilightKiddy@scribe.disroot.org 2 points 18 hours ago

You can use less. There are also specialized ones for that purpose like bat.

[-] shark_byte@lemmy.zip 15 points 1 day ago

yeah sure but the command is literally written for the humor.

[-] dan@upvote.au 18 points 1 day ago

I know, but I just wanted to mention this since a lot of new Linux users end up using cat this way :)

[-] Grail@multiverse.soulism.net 4 points 22 hours ago
[-] shark_byte@lemmy.zip 3 points 1 day ago

ohhh but it's all humor that's the point of the post.

I mean as a new Linux user, I won't take anything from a humor group seriously.

[-] daychilde@lemmy.world 2 points 13 hours ago

I would.

I'd be careful of jokes, sure, but geeks often can't help have real discussions. Like in this very thread

this post was submitted on 03 Aug 2026
375 points (98.0% liked)

Programmer Humor

32608 readers
650 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 3 years ago
MODERATORS