August 22, 2019

5 Tools and Tricks for an Easier Terminal Time

by James Mawson

Ahh, the terminal.. it’s a love/hate dealio.

When you know exactly to type, it’s the quickest and most convenient thing ever. But even the most trivial typo will ruin that.

Which is why the phrases “command line” and “user friendly” are so rarely paired. So here’s some tips to make it way easier:

TLDR

TLDR pages are a quicker and more informal take on the man page. They explain commands very simply and illustrate them with practical examples.

There are a number of clients available for TLDR – the Node.js version is recommended as the most mature, but it’s available in many implementations.

Click here for installation instructions.

please

You may have already heard of !! in bash: it repeats your last command. It’s commonly paired with sudo when something fails without root privileges.

If sudo !! works for you, there’s every reason to be happy with it. My problem was that it would slip my mind for just long enough to be less convenient than using the arrow keys and typing it all out like a schmuck.

So instead I use the alias please, which I can always remember, even when my mind is mush after a long day.

Setting this alias is a little fiddly. If you try to do it the obvious way, bash replaces the double exclamation marks with the previous command before assigning the alias. So it ends up doing something completely different – and perhaps disastrous. Gahh!

Use this instead:

alias please='sudo $(fc -ln -1)'

To make it permanent, add it to the bottom of your ~/.bashrc file with this command:

sudo nano ~/.bashrc

With this little tweak, when I’m told I don’t have enough privileges, I just type the magic word please and it works.

fuck

Is politeness getting you nowhere? Maybe try swearing. Specifically, try saying fuck.

I first installed this for the same reason I installed cowsay: because it’s hilarious. It was only after having it on my machine for a little while that I realised that, hey, this is incredibly useful too.

The basic premise here is that when you get a command wrong, you type fuck in frustration and it suggests corrections for you.

There’s a long list of heuristics – far more than I really understand to be honest. In practice, I tend to use it for typos and misspellings, which I do all the time. It seems to always know how to fix them.

Fuck is installed using the pip package installer for Python 3. Click here for full installation instructions.

time cat

This sounds so much like a Saturday morning cartoon that never actually existed in my childhood but probably really should have.

What it is though, is two well known commands combined in a novel way to make a stopwatch. Just press ctrl + c to stop it at the right time.

I find this handy to get rough timings of things happening in windows or, more often, in a web browser. It’d be a bit silly to use this to time a command line operation. Using time in the more conventional way is much easier and more accurate.

There’s no need to install this; you have these commands already.

cd –

It’s a common enough thing to need to switch between two different directories. The way I used to do this was just to press the up key until I found the last cd command I’d typed for that directory.

There’s an easier way to do this though. You can switch back to the last directory you were in by typing:

cd -

You can use this as many times as you like to switch between the same two directories.

Do you have any cool tools or tricks up your sleeve to make this easier? Let me know in the comments!

Comments