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

Programmer Humor

32747 readers
2708 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
 

ahh

~$ which cat
top 50 comments
sorted by: hot top controversial new old
[–] dan@upvote.au 86 points 1 week ago* (last edited 1 week ago) (6 children)

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 75 points 1 week ago (1 children)
[–] shark_byte@lemmy.zip 18 points 1 week ago (2 children)

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

[–] ranzispa@mander.xyz 11 points 1 week ago

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

[–] MonkderVierte@lemmy.zip 9 points 1 week ago (1 children)
[–] shark_byte@lemmy.zip 6 points 1 week ago
[–] lokalhorst@feddit.org 18 points 1 week ago* (last edited 1 week ago) (4 children)

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

[–] mote@lemmy.ca 21 points 1 week ago

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

[–] dan@upvote.au 13 points 1 week ago* (last edited 1 week ago) (1 children)

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 6 points 1 week ago (1 children)

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

[–] dan@upvote.au 6 points 1 week ago (1 children)

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

[–] not_IO@lemmy.blahaj.zone 2 points 6 days ago

i don't think you can but idk why that's by I'm asking

load more comments (2 replies)
[–] qqq@lemmy.world 17 points 1 week ago (1 children)

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

[–] shark_byte@lemmy.zip 16 points 1 week ago (1 children)

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

[–] dan@upvote.au 19 points 1 week ago (3 children)

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 5 points 1 week ago (1 children)
load more comments (1 replies)
load more comments (2 replies)
[–] ranzispa@mander.xyz 12 points 1 week ago (2 children)

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 1 week ago (1 children)

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

program <file | grep | cut
[–] jxk@sh.itjust.works 15 points 1 week ago (3 children)

And <file program | grep | cut works too

[–] Digit@lemmy.today 1 points 5 days ago

These <file things must be for different shells than the ones I use.

load more comments (2 replies)
load more comments (1 replies)
[–] eager_eagle@lemmy.world 11 points 1 week ago (1 children)

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 week ago (1 children)

< file.txt grep thing also works.

load more comments (1 replies)
[–] A_norny_mousse@piefed.zip 29 points 1 week ago (2 children)

Another all-time favorite:

$ man woman  
No manual entry for woman  
[–] Digit@lemmy.today 2 points 5 days ago

Huh. ... I could have swore there was a woman. I even package searched, even in overlays... no woman.

digit 20260807 tyson gentoo /home/digit % whereis woman
woman:
digit 20260807 tyson gentoo /home/digit % which woman
which: no woman in (/bedrock/cross/pin/bin:/bedrock/bin:/usr/local/bin:/usr/local/sbin:/opt/bin:/opt/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/snap/bin:/home/digit/bin:/usr/games/bin:/usr/games:/bedrock/strata/devuan/usr/libexec/xscreensaver:/home/digit/.cargo/bin:/bedrock/cross/bin)
digit 20260807 tyson gentoo /home/digit % apropos woman
woman: nothing appropriate.

digit 20260807 tyson gentoo /home/digit % man cry
No manual entry for cry
digit 20260807 tyson gentoo /home/digit % whereis cry
cry:

No woman.

No cry.

$ touch woman
touch: cannot touch 'woman': Permission denied
[–] red_tomato@lemmy.world 22 points 1 week ago (1 children)

tac is a cat but faced the other way

[–] shark_byte@lemmy.zip 12 points 1 week ago

ohhh let me check it out lol

[–] exu@feditown.com 16 points 1 week ago (2 children)

I've been using a slightly customized bash-cat for years now. Still makes me smile when I see it

[–] shark_byte@lemmy.zip 6 points 1 week ago

yeah I just checked it out it's cute

load more comments (1 replies)
[–] rumba@lemmy.zip 13 points 1 week ago (3 children)
load more comments (3 replies)
[–] anotherspinelessdem@lemmy.ml 12 points 1 week ago (1 children)
[–] darth_grunkus@lemmy.world 14 points 1 week ago* (last edited 1 week ago)
[–] Dyskolos@lemmy.zip 10 points 1 week ago

I was today's years old to finally notice the cat-head-tail thing...

But it also just recently dawned upon me why pacman has those weird "c" as progress indicators...

I'm not a smart man...

[–] TwilightKiddy@scribe.disroot.org 10 points 1 week ago (2 children)

I always thought it's

head | cat | tail

It, of course, waits for an input, which brings up the one and only question...

Have you fed your cat?

[–] Digit@lemmy.today 1 points 5 days ago (2 children)

I'm scared to run that.

Is that like some kind of fork bomb?

Or is it just a tubular cat?

[–] AVincentInSpace@pawb.social 2 points 2 days ago

it won't... do anything

it'll wait for you to type ten lines (the default for head without arguments), buffer them (bc tail must buffer its input), then spit them back at you, and exit

  • head takes the first N lines of its input (if -n <number> is not specified, the default is 10 lines, and default reading from stdin, which in this case is your terminal) and prints them to its stdout (which thanks to the pipe, goes directly to cat's stdin), then signals end-of-file.
  • cat accepts any number of filenames and conCATenates them (hence the name), writing their contents one after the other to stdout. with only one file as argument (the most common case in practice) it will simply write that file's contents to stdout. with no arguments (as in this case) it will simply copy everything from its stdin (in this case head's stdout) to its stdout (in this case tail's stdin). the cat command could be completely omitted from this invocation (leaving simply head | tail) and it would work exactly the same.
  • tail reads its entire input (like head, it defaults to reading from stdin unless a filename is specified) and buffers it, then, when the end of the file is reached, it prints the last N lines is read (again defaulting to 10 unless -n <number> is specified) to stdout (in this case your terminal).

put all together, head will wait for you to type a line, then will pass it on to cat, which will then immediately pass it on to tail, which will add it to a buffer and wait for another line. rinse and repeat until you have typed 10 lines, and then head will exit and the pipe between it and cat will close. cat, noticing the closed pipe, will exit in turn, causing the pipe between it and tail to close. tail, seeing an end of file signal on its input pipe, will cough up the last 10 lines in its buffer and then exit. since head only sent it 10 lines, this is the entirety of its input. so it will spit back everything you typed.

If you press Ctrl+D to send head an end-of-file signal before you have typed 10 lines, head will exit immediately, causing cat to exit, causing tail to output everything it had in its buffer so far.

Put suspicious cats into sandboxes until it's proven that they are crewmates.

[–] shark_byte@lemmy.zip 6 points 1 week ago

of course look meow meow so loud

[–] Jankatarch@lemmy.world 10 points 1 week ago (1 children)

Bat is my favorite command to date.

[–] shark_byte@lemmy.zip 7 points 1 week ago (1 children)
[–] Digit@lemmy.today 1 points 5 days ago

man bat | bat

[–] Avicenna@programming.dev 8 points 1 week ago* (last edited 1 week ago) (1 children)
[–] LedgeDrop@lemmy.zip 12 points 1 week ago (1 children)
[–] HamsterRage@lemmy.ca 8 points 1 week ago (3 children)

For the past 30 years or so, my brain always tells me to type "last" instead of "tail". This usually results in some kind of "Permission denied" message that confuses me for a few seconds.

load more comments (3 replies)
[–] reader@lemmy.zip 5 points 1 week ago (4 children)
load more comments (4 replies)
load more comments
view more: next ›