Neat tips! thanks
We all know !! but it's mostly just used to sudo !!
I find !$ (which is last argument of the last command) incredibly useful:
#make a directory and go to it
# OR even better
# move then edit a file
mv ~/somefile.txt ~/renamed.txt
# edited a file, now add it to git
git add !$
There's a whole slew of ! commands but !$ is one I use all the time.
You can also use esc + . instead of !$. I find more natural and useful if you need to fix a typo.
Even better! Thanks
P.S. For posterity, all of these work just as well in zsh.
Funny $_ is the exact same as !$. There's always more to learn 😀.
Quick note, if you are using the command edit/replace feature and are using a conditional command construct (echo "first command" && echo "second command!") the ^foo^bar syntax only replaces the first instance of the searched text.
echo "first command" && echo "second command!"
To replace every instance of that searched text, you have to use !!:gs/foo/bar; going back to my first example:
To replace all the instances of command in...
...you have to execute...
Further reading: Stack exchange
Yup I found out about it sometime after I wrote the original post almost 10 years ago. Thanks for the reminder!
Small correction: bash completion for SSH looks for $HOME/.ssh/config, not authorized_keys
Yikes my bad. Actually it should be $HOME/.ssh/known_hosts file for auto completing host names. You won't find host names in $HOME/.ssh/config unless you've explicitly put them there, but every host you connect to gets saved in known_hosts by default.
Yes, it does, but bash-completion does not read hosts from known_hosts - at least on my Ubuntu 16.04 machine.
It will, however, read both hostnames and host aliases from config.
Nice writeup! I definitely have look more into /dev/*!
I learn something new that unix tools can do basically every day 😄 In case someone is interested, I try to share those findings on a separate Twitter account: twitter.com/qvlio
So cool! I also use $_ for the arguments of the last command, echo "something" $_ will be "something"
+1 for the first one. 👌👌
I love shells. They are so powerful. If I can't use one on any of my devices I feel naked
We’re a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.