One thing I find life-changing is to remap the up arrow so that it does not iterates through all commands, but only those starting with the characters I have already written. So e.g. I can type `tar -`, then the up arrow, and get the tar parameters that worked last time. In zsh this is configured with bindkey "^[OA" up-line-or-beginning-search # Up bindkey "^[OB" down-line-or-beginning-search # Down
Once you start using CTRL+r, you may find that you never reach for up arrow again.
Shell Tricks That Make Life Easier (and Save Your Sanity)
241–250 of 287 posts
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#242Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#243I'd advise against using sudo !! though since it adds the command to history and then it's very easy to accidentally trigger, running some undesired command as root without any prior confirmation. IMO pressing up, Ctrl-A and typing "sudo " isn't much longer but saves you from running unknown commands as root by accident
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#244Its almost ironical that we still use the Terminal - and many use it like in the eighties using Bash - and seem to have forgotten that we should invent a better terminal & shell than doing all the workarounds to handle the quirks of the current systems.
Make a better system, and we'll consider using it. A Terminal + Bash/ZSH is soooo sticky because they are VERY good at what they do once you learn the basics and quirks. And now with LLMs, CLIs are even better because LLMs talk in text and CLIs talk in text. Microsoft tried with PowerShell to design a better system; it "technically" is better, but not "better enough" to justify the cost of switching (on Linux). The s…
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#245Its almost ironical that we still use the Terminal - and many use it like in the eighties using Bash - and seem to have forgotten that we should invent a better terminal & shell than doing all the workarounds to handle the quirks of the current systems.
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#246Earlier quoted context omitted.
What is it like to be this proud of not learning the tools you use? Do you really think several paragraphs to an agent that may or may not be correct is the "easy" way compared to just checking the manual for the flag you want? I will never understand people like you.
Tools are means to end. They don't matter much to me.
"Tools are just a means to an end" means you need to not get attached to a tool if it's not doing the job. It doesn't mean you don't need to understand your tools.
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#247One thing I find life-changing is to remap the up arrow so that it does not iterates through all commands, but only those starting with the characters I have already written. So e.g. I can type `tar -`, then the up arrow, and get the tar parameters that worked last time. In zsh this is configured with bindkey "^[OA" up-line-or-beginning-search # Up bindkey "^[OB" down-line-or-beginning-search # Down
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#248Using the terminal becomes much more cozy and comfortable after I activate vim-mode. A mistake 3 words earlier? No problem: 3bcw and I'm good to go. Want to delete the whole thing? Even easier: cc I can even use v to open the command inside a fully-fledged (neo)vim instance for more complex rework. If you use (neo)vim already, this is the best way to go as there are no new shortcuts to learn and memorize.
A mistake 3 words earlier? No problem: 3 Alt-b Alt-d
Want to delete the whole thing? Even easier: Ctrl-U
I can even use Ctrl-X Ctrl-e to open the command inside a fully-fledged EDITOR instance for more complex rework.
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#249Using the terminal becomes much more cozy and comfortable after I activate vim-mode. A mistake 3 words earlier? No problem: 3bcw and I'm good to go. Want to delete the whole thing? Even easier: cc I can even use v to open the command inside a fully-fledged (neo)vim instance for more complex rework. If you use (neo)vim already, this is the best way to go as there are no new shortcuts to learn and memorize.
This reminds me of an excerpt from an old Emacs manual: . . . if you forget which commands deal with windows, just type @b[ESC-?]@t[window]@b[ESC]. This weird command is presented with such a benevolent innocence as if it's the simplest thing in the world. I think the better advice for command-line editing would be to set up the mouse.
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#250One trick I use all the time: You're typing a long command, then before running it you remember you have to do some stuff first. Instead of Ctrl-C to cancel it, you push it to history in a disabled form. Prepend the line with # to comment it, run the commented line so it gets added to history, do whatever it is you remembered, then up arrow to retrieve the first command. $ long_command $ #long_command $ stuff_1 $ stu…
Fwiw, in Bash, alt-shift-3 will prepend the current command with # and start a new command.