Shell Tricks

This is as much a reference for myself as anything. But here are a few (bash) shell tricks I’ve picked up over the year. Some of them are bonehead simple, but it still took me a while to find out about them.

Enable jumping words in iTerm
This is such a basic one it’s part of my default profiles on everything. No more holding down the arrows keys, now you can just skip words to get where you need to.

Use previous commands
This is a two-fer. Firstly, using the up and down arrows will scroll through recent commands, which can be really useful. But more importantly is the history command.

history will show your sessions commands
history 5 will show the last five

And history leads on nicely to…

The bang operator
Hey, I don’t name these things. But the bang operator (or exclamation mark as everyone else knows it), is really useful for interacting with your previous commands.

!! will execute the last command again, ergo…
sudo !! will execute the last command with sudo
!5 will execute the command you ran 5 lines ago

Amazingly Digital Ocean have a pretty decent guide on using the history operator.

The toolbox
The first few are small programs that are just handy day in, day out. Learn how to use these programs and learn them well.

cat for viewing stuff
more for viewing big stuff
tail for viewing the end of stuff
tail -f for watching the end of stuff
grep for finding stuff
touch for making stuff
open for opening stuff

I’ve intentionally missed out pipes, but this is where they shine. Pipe the output of a file through grep and dump it somewhere else.