Let's here them!
For further actions, you may consider blocking this person and/or reporting abuse
Let's here them!
For further actions, you may consider blocking this person and/or reporting abuse
Jon -
Sergei Vorniches -
Samihan -
Arjun Rao -
Top comments (79)
Oh my, I love this topic! Here comes a wall of text:
Using
!!
redo the last command, which is specially useful for those times you forgot to run that big annoying command as sudo, you can just runsudo !!
this time.Also, if you just
cd
without arguments, you end in your home. Sometimes thats useful.On the same theme of
cd
, you cancd -
to go to last directory. I love this! Also works withgit checkout -
to go to the last branch!Another one is that if you use bash or zsh (and probably fish?) in emacs mode, which is the default, there are some commands that are very helpful:
Control + w
Deletes one word behind, like control + backspace on some editorsControl + k
Deletes everything from cursor to the end of the line. Maybe only the start of your command was right and you don't want to retype a bunch of things.Control + u
Deletes everything from cursor to the start of the line. Maybe only the end of your command was right.Control + y
Paste the last thing you deleted using the above commands. A god send.Honorable mentions:
Control + e
andControl + a
go to the end of the line/start of the line, respectivelyControl + p
is the same as up arrow, useful if you think the arrow keys are far awayControl + n
is the same as down arrow. Ditto aboveControl + m
is the same as hitting enterControl + i
is the same as tab (completion)I particularly use control + p a lot!
And as a side note, if you don't want to go
sudo !!
like I suggested initally, you can always go up in history (control+p
or up arrow, you name it), cut everything withcontrol+u
, writesudo
and then paste it withcontrol+y
. Really good commands here!And you can always customize what key presses do with
bind
in bash andbindkey
in zsh.If you are on bash, you can see all commands with
bind -P
andbind -p
. To set different things, you can run (or put in config file, eg,.bashrc
) something likebind '"\C-f":clear-screen'
.If on zsh though, just
bindkey
is enough to list them, andbindkey "^F" clear-screen
to remap.I personally use
control + f
as clear screen for so long, that when I'm at a computer that does not have it I feel lost initially, which is arguably a downside to customization of hotkeys, specially for commands that already have a simple command, like clear screen. Maybe you should not use the mapping I do! 😅!!
is nice, but it's really only the beginning. If you force yourself a bit to use more complex expansions even when they slow you down at first, you'll quickly end up making your life infinitely easier with things like!?vim?:gs/foo/bar
ormv some_long_file_name.jpeg !#:$:r.jpg
(although that last one could also be done easily withrename "s/jpeg$/jpg/" some_long_file_name.jpeg
, of course)Even simple things like
mv file.{txt,md}
already feels nice to do.rename
is a good program, by the way!But the most game changing learning was on how to do some shell scripting. How to use grep, regexes, sed, cut, cat and even for loops. Simply a whole new dimension opens up to you, and it's all in your hands.
Add
awk
to that ...control + l
is a native hotkey for clearing screen. Maybe you would want to switch to that?Yes, but when I started using tmux, I remapped
control + l
to something else (switch to right pane). That's when I remappedcontrol + f
. Pretty much a sequence of changing native hotkeys that just pile up for me when I'm not with my computer... 😅Customizing things sure is nice, but having standards are probably nicer. We should always proceed with care when customizing!
Amazing write up!! You have listed down all my favourites and few I didn’t know before. Thanks.
I always forget how to bind keys, so I need to fallback to Ctrl+R, on a VPS or un-setup machines.
I tried selfish
Thanks a lot
I'll go first
Ctrl+R Autocomplete with Bash is a Life Saver
Ben Halpern ・ Jan 17 '17 ・ 1 min read
Tack on fzf and you have gold.
Seconded on fzf, only external CLI utility that I will recommend
what? fzf is the gold!
(joke)
Using Ctrl+O after going back in the history (either with arrow keys or Ctrl+R) will populate the next prompt with the next item in the history. Great if you have multiple commands you want to execute one after the other repeatedly.
Yep that would be my #1 too - control-R all the way! Oh and I use
cd -
all the time ...If you are going to take the time to setup your command line real nice, then you need a dotfiles repo, if you have a dotfiles repo you need to stow.
2 minutes to stow
Waylon Walker ・ Jan 9 ・ 1 min read
I always thought the stow docs jump right into the weeds and make it sound very complicated, but It's pretty simple if you worry less about the implementation.
TL;DR. The first step of being master of any command:
tldr.sh/
if, during development, you
you should use bash or powershell to automate whatever you're doing.
Computers are way better than keeping stuff in mind than people. I'm writing scripts for every non-throwaway project by now
Latest one for the appwrite hackathon goes
This little bit of code saves me at least 1 minute whenever I want to bring up or down my dev server. Took like 5 to write. And I have to memorise only a few commands instead of several. Totally worth it
Yep. I even write scripts for the simplest of tasks now:
These micro-scripts can seem like a waste of time while writing them, but after calling them 10 or 20 times, you've already saved more time than it took to set them up.
set -e
Will also exit a skript if a command inside fails
No it won't. Look at the script again ;)
fish!
fishshell.com/
I have a series of 7th articles with a lot of them for ZSH:
dev.to/equiman/series/11407
Another to config zsh + power level 10 on macOS:
iTerm2 + Oh My Zsh! + Powerlevel10K best terminal combination for Geeks!
Camilo Martinez ・ Sep 25 '18 ・ 5 min read
But the most useful for me is config the fingerprint reader to use on the terminal when asking for a password:
How to use MacOS's Touch ID on Terminal
Camilo Martinez ・ Oct 8 '19 ・ 1 min read
git diff
more of a git tip but it saves me time and trouble seeing if/what differences I have between my branch and main.Only 1 thing,
Learn a liitle bit of shell scripting, it changes how one works with a terminal/CLI
Knowing a bunch of things and putting them together to improve your workflow as developer everyone should strive for.
My Favorite Bash Tips, Tricks, and Shortcuts
Yechiel Kalmenson ・ Jan 11 '21 ・ 3 min read
One of my recently acquired command line tip, create this function
usage
No need to create a python process or node process ( or any other interactive shell ) for quick calculation. It just takes the mathematical query and throw it to BC which then return the result.
In case it isn't obvious, Question mark
?
is just a name of function. You can choose anything else as long as it doesn't conflict the system.AlsoI should have checked on my machine before bashing out here, My casio calculator outputs 1 because of implied multiplication taking precedence, so does what we are taught in schools in India, but apparently precedence of implied multiplication is standardized to be ignored since 1917.bc
is a mathematical tool, it follows bodmas or pemdas order of operation. So6 ÷ 2(1+2)=
is equal to 1, not 9, not 7, or any other thing you saw on facebook.Sorry, but
6 ÷ 2(1+2)
is just 9, indisputably.Bodmas, pemdas or any other weird word is just a pitfall to trick people into mistakes, and gladly I have never heard such terms in school. Division and multiplication are performed in the order they appear, it could not be simpler. Division, in fact, is multiplication, just like subtraction is the same as addition. When you divide by 5, you are in fact multiplying by the inverse of 5. There is no reason to perform multiplication before division, since they are the same thing.
I couldn't believe BC would output 1, so I opened a terminal and ran it, and of course it showed 9 in the screen.
Well apparently, In India, we were taught the older method. I did some search and find this video from "mind-your-decision" and what we were taught is the older 1917 order of operation, where parentheses next to number has special exception. My old casio calculator actually outputs "1", because they have implied multiplication
I know that division and multiplication have same level of order and hence calculated left to right. Bodmas doesn't mean addition before subtraction, but it does mean division(or multiplication) happens before subtraction(or addition) and exponents(or log) happens before them, and brackets always have higher priority. The operators with same specificity are solved left-to-right.
Thanks for correcting me. I wrote it as a sarcasm on all the stupid fb posts and twitter polls that have been going around my feeds, but turns out it was a facepalm moment. "Implied multiplication" is still taught in schools in India.
Don't edit bash scripts while it is running; even when it takes forever.
In contrast, other types of scripts, like Python, can be edited for the next run.
I also have seen
set -e
. I wonder if it can be safely used with other kind of logics?To check what specific server is domain running at:
It's easier to just do
ping somewebsitegoeshere.com
; it's technically the wrong command, but easier to remember and quicker to type ;)Switch to the previous directory you were in:
cd -
A similar command exists with Git and branches:
git checkout -
or simplygco -
since git-checkout is often aliased to "gco."I've so many to tell like using up and down keys, using
\
and&&
, checking bash history withalso using !! to redo last command