Spyke

Syndicated from the fediverse. Read and engage on the original instance.

View original on lemmy.zip

61 replies

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...

8
lemmy.ca

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.

6
lemmy.ca

Yes, but it shows information about recent/current logins and requires access a file called wtmp (or something like that, off the top of my head), and that requires privileged access.

My usual use case where I mix it up is looking at a log file and and I just want to see the last few entries. So my brain 🧠 tells my fingers to type "last logfile", and when I get the permission message it tells my mouth to go, "Doh!".

4

yeah I looked it up

this will be handy

~$ last reboot
~$ last -s -7days
2
dan
upvote.au

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).

83

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

11
qqqreply
lemmy.world

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.

15
ranzispareply
mander.xyz

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.

11
danreply
upvote.au

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

program <file | grep | cut
8

Thanks - I didn't know this either!

1
lokalhorstreply
feddit.org

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

17

If it's really long, I use less , because it breaks it up into navigable pages instead of filling your entire buffer. :)

Never knew about just using < though! Cool!

1
danreply
upvote.au

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.

13

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

5

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

20
lemmy.world

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

10
shark_bytereply
lemmy.zip

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

15
danreply
upvote.au

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

18
shark_bytereply
lemmy.zip

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.

4
rumbareply
lemmy.zip

Reverse chronological order, mostly

tac log.txt |head # would give you newest first

no good for sort because sort already supports -r

no need it for tail on large files because tail already skips to the end.

I do a lot of impromptu bash to sus crap out of logs.

when you're balls deep in

cat log|grep -v foo| rev|cut -f 1-3 -d \ | |rev

Sometimes tac comes in clutch.

3

That's fair. I'd usually just use less and drop to the end. My use cases would always need the older log before a newer log though because that's the start of the problem. At least that's how I operate.

4
exu
feditown.com

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

14

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?

7
selreply
lemmy.world

Be careful now, 2000/2010 Linux terminology can be taken as an insult in 2026. /s

I’m tired of this stupid coddling bullshit with the influx of new Linux users. If you can’t read don’t use Linux. Simple. 😂

2

In order of approachability:

Man pages.

Also Arch Wiki.

Also excellent books by NoStarch Press.

... Or did I miss a joke? Hehe

1