this post was submitted on 11 Apr 2026
250 points (98.8% liked)

Technology

84143 readers
2917 users here now

This is a most excellent place for technology news and articles.


Our Rules


  1. Follow the lemmy.world rules.
  2. Only tech related news or articles.
  3. Be excellent to each other!
  4. Mod approved content bots can post up to 10 articles per day.
  5. Threads asking for personal tech support may be deleted.
  6. Politics threads may be removed.
  7. No memes allowed as posts, OK to post as comments.
  8. Only approved bots from the list below, this includes using AI responses and summaries. To ask if your bot can be added please contact a mod.
  9. Check for duplicates before posting, duplicates may be removed
  10. Accounts 7 days and younger will have their posts automatically removed.

Approved Bots


founded 2 years ago
MODERATORS
top 50 comments
sorted by: hot top controversial new old
[–] MummifiedClient5000@feddit.dk 42 points 2 weeks ago (3 children)

Nothing gets my nerdrage on more than using CTRL+w in a browser-based shell and closing the tab.

[–] lemmydividebyzero@reddthat.com 7 points 2 weeks ago

Yeah, annoying that it has different meanings.

[–] toynbee@piefed.social 5 points 2 weeks ago (2 children)

Pretty much the one and only good thing about work forcing us to switch from Linux laptops to Macbooks.

[–] LiveLM@lemmy.zip 7 points 2 weeks ago (2 children)

I hated the Command + C and Command + V for Copy / Paste until I realized it meant not clobbering ^C in the terminal. Instantly loved it.

[–] toynbee@piefed.social 5 points 2 weeks ago

The biggest issue I have with it is that I have Linux on all my personal systems and OSX on my work laptop and sometimes switch rapidly between them.

My fingers don't seem to adapt as quickly, though, and I often press the wrong combination between them.

[–] MadMadBunny@lemmy.ca 1 points 1 week ago

Yeah, they knew what they were doing back then…

[–] MummifiedClient5000@feddit.dk 6 points 2 weeks ago

The mixed used of the command key and CTRL on Macs has tricked me to pressing command+w in a terminal window quite a few times.

[–] Undearius@lemmy.ca 37 points 2 weeks ago (4 children)

I've seen a few of these "shell tricks" articles. This one I actually learned quite a few, which I will promptly forget when I actually need to use them.

load more comments (4 replies)
[–] LedgeDrop@lemmy.zip 26 points 2 weeks ago (1 children)

This is a good article, especially if you're the lucky 10,000.

[–] HuudaHarkiten@piefed.social 9 points 2 weeks ago (1 children)

I was one of the 10 000. Again!

[–] IratePirate@feddit.org 6 points 2 weeks ago (1 children)

I am too - every single day. If I didn't know better, I'd think I'm stupid.

[–] HuudaHarkiten@piefed.social 6 points 2 weeks ago* (last edited 2 weeks ago)

I know better, I am stupid ^__^

edit: evidence of my stupidity is that I couldn't even get one of those emoji faces done right

[–] CallMeAl@piefed.zip 12 points 2 weeks ago (2 children)

Great article but this shouldn't be called "Tricks" it should be called Shell Basics. I'm old enough to remember taking an Intro To Unix course and there was an entire day on the shell where these types of commands were presented as essential learning.

[–] frongt@lemmy.zip 4 points 2 weeks ago* (last edited 2 weeks ago)

Yeah. All of those and more are in the manual: https://www.gnu.org/software/bash/manual/bash.html#Readline-Bare-Essentials

Yes, I know there are other shells than bash, but it's the one included as default almost everywhere, and where the article starts too.

[–] toynbee@piefed.social 2 points 2 weeks ago

A fact that I like to share from my personal history: I took four years to graduate from a two year college because I was taking every computer class they offered ... Except that I skipped "intro to Unix" because when was I ever going to use that?

My entire career has been largely based on knowing how to use Linux.

[–] Badabinski@kbin.earth 10 points 2 weeks ago (1 children)

set -e: Exit on error. Very useful, but notoriously weird with edge cases (especially inside conditionals like if statements, while loops, and pipelines). Don’t rely on it blindly as it can create false confidence. (Pro-tip: consider set -euo pipefail for a more robust safety net, but learn its caveats first.)

while I appreciate that the author mentions how weird this is, nobody is going to learn all the caveats correctly. Don't use set -e. Don't use set -e. Don't use set -e. It's a shit ass broken ass fucked feature that half of nobody understands well. Here's a great wiki page explaining why it's trash: https://mywiki.wooledge.org/BashFAQ/105

People like Go, and Go requires you to manually and stupidly handle every possible error case. Why not do the same for shell? It's really quite easy:

#!/usr/bin/env bash
echoerr() { echo "$@" 1>&2; }

die() {
  message="$1"; shift
  exit_code="${1:-1}"
  echoerr "$message"
  exit "$exit_code"
}

temp_dir="$HOME/tmp"
mkdir -p "$temp_dir" || die "Failed to make persistent temporary dir $temp_dir"
lc_dir="$(mktemp -d -p "$temp_dir")" || die "Failed to make target dir in $temp_dir"

Look at that, descriptive error messages! And it doesn't depend on a shell feature that is inconsistent between versions with no good documentation about all of the fucked up caveats.

[–] coriza@lemmy.world 1 points 2 weeks ago* (last edited 2 weeks ago) (1 children)

You know.... I was about to reply with "I use set -e and I love it, but them I read the link and it gave me flashbacks. In a previous work at some points I programmed way more in bash than the languages I was officially hired to program into, and I run in some many of this edge cases, I think almost all of the ones mentioned in the link, including doing the workarounds mentioned. two that standed out to me was local var=$(fail) and if f(). Side note, I remember finding a bug in declare (I don't remember exactly, but one of the flags, maybe -l to make a local variable was not working) and was só excited to fill a bug report but then I saw that it had already fixed in a newer bash release.

Anyway, In the end if I recall correctly I never settled in a one fixed approach, I distinctly remember adding set -eu to a bunch of scripts but also remember having to set +e in some cases like when sourcing other scripts and also adding the suggested foo || die combo a bunch"

I think in the end my approach was the same as rking's at the end of the linked text, I used it but not relied on it. And I guess using too much bash made me paranoid and I heavily tested every line for all sorts of error cases. I think set -e is good when debugging when the thing is not working, especially because bash also suffers to lack a good debug and tracing environment, leaving you to set a bunch of stuff just to have a trace of your script and see what it is doing.

[–] toynbee@piefed.social 3 points 2 weeks ago

I remember a while ago - when, like in your anecdote, I mostly coded in bash - I had a dream that I found out people were invoking my scripts in a manner that essentially overrode settings that might (or, in my case, might not) have been set at the beginning of the script.

This never (AFAIK) happened in waking hours, but I was very offended in the dream.

[–] Luckyfriend222@lemmy.world 8 points 2 weeks ago

CTRL + W? Why did I only learn about this today? About 20 years too late! Thank you.

[–] voytrekk@sopuli.xyz 6 points 2 weeks ago

Great article. I have leanred a lot of these tricks and shortcuts over the years yet I still learned quite a few things that would be useful.

Particularly that you can paste what you cleared with ctrl+U. No more opening a second tab or creating an additional ssh connection.

[–] MonkderVierte@lemmy.zip 5 points 2 weeks ago* (last edited 2 weeks ago)

Please make the site respect my color setting by default.

It's a sunny spring day.

[–] ivanafterall@lemmy.world 4 points 2 weeks ago (1 children)
[–] Tikiporch@lemmy.world 2 points 2 weeks ago (1 children)

Is that a pea, or one of those round candy coated chocolate things I can't remember the name of?

[–] ivanafterall@lemmy.world 2 points 2 weeks ago* (last edited 2 weeks ago) (1 children)

Sixlets? I assume it's a walnut based on the shells.

[–] ranzispa@mander.xyz 4 points 2 weeks ago (1 children)

Never seen small spherical walnuts.

[–] No1@aussie.zone 2 points 2 weeks ago

They're quite common. Usually called 'peas'.

[–] brsrklf@jlai.lu 4 points 2 weeks ago (1 children)

~~I was expecting some cool Mario strats~~

I'm always using "clear" to just get rid of my console's output. I think it has something to do with me remembering I used that on my old 80's computer, trying it out on a bash long after that and "oh, that works here too, that's convenient".

Reset looks like it does more stuff, but I don't know if that's useful for this use case.

load more comments (1 replies)
[–] shellington@piefed.zip 3 points 2 weeks ago

Wow thanks just picked up some great tricks.

Especially sudo !!

[–] john_lemmy@slrpnk.net 3 points 2 weeks ago* (last edited 2 weeks ago)

I use CTRL+D a lot, but I didn't know it was a send EOF command. Why does that close the session / terminal?

Also, the undo shortcut is also pretty nice (CTRL+_ ?) and missing there

[–] Appoxo@lemmy.dbzer0.com 2 points 2 weeks ago

Unrelated but I like your username. Reminds me of a certain instance ;)

[–] amateurcrastinator@lemmy.world 2 points 2 weeks ago

On a new rocky 10 install Ctrl + R doesn't do much. I can't find commands I know I typed. I can't be bothered to find out why

[–] corsicanguppy@lemmy.ca 1 points 2 weeks ago (1 children)

Never tell the emacs haters why ctrl- and alt-stuff is just so familiar to the rest of us.

[–] ExLisper@lemmy.curiana.net 1 points 2 weeks ago (1 children)

Here's a real shell trick for you:

Remove the arrow keys from you keyboard for a month or two.

Seriously, do it. Do you know how to jump to the beginning of the line? The end? Move one word back? One character back? After a month without arrow keys you will know, trust me.

[–] __hetz@sh.itjust.works 7 points 2 weeks ago* (last edited 2 weeks ago) (2 children)
[–] ExLisper@lemmy.curiana.net 3 points 2 weeks ago

I didn't know that one. I use vi all the time but my brain can't handle it in the command line. Two different muscle memories clash.

[–] thax@lemmy.dbzer0.com 1 points 2 weeks ago

I love vi cli mode. vi-mode with OpenBSD's ksh is my jam.

[–] FlowerFan@piefed.blahaj.zone 1 points 1 week ago

website is down for me?

[–] MonkderVierte@lemmy.zip 1 points 2 weeks ago* (last edited 2 weeks ago) (3 children)

alias please='sudo !!' would that work?

Edit: nope. Why not?
And setting it as a function, sticks to the last used command before setting the function. Fuck.

load more comments (3 replies)
[–] mazzilius_marsti@lemmy.world 1 points 2 weeks ago

Ctrl + L is very nice..... holy shit

[–] No1@aussie.zone 0 points 2 weeks ago

Shell?

Surely systemd has absorbed it by now!

load more comments
view more: next ›