Terminal illness
selbekk

selbekk @selbekk

About: I'm a full stack dev that specializes in React, English Bulldogs and beer based coding meetups

Location:
Oslo, Norway
Joined:
Mar 8, 2019

Terminal illness

Publish Date: Jul 5 '20
24 6

You don't have to be a Linux hacker to use the terminal to be productive. Here's a few tips I've picked up the last couple of years that might make you even iller in the terminal.

Just a disclaimer - I'm no terminal professional. Yet, over the 7 last years, I've learned a few very nice-to-know techniques that you might not have heard of. There's no guarantee that you'll learn anything from this, but a pretty bit chunk of my readers might learn at least a thing or two.

A little side note here - these commands are meant for OSX only. They might work on Linux or WLS, but I haven't tried them out.

Use the clipboard!

Every once in a while, you have some data in the clipboard that you want to use somehow, or you want to copy the output of a command into the clipboard. Either way - it's very possible to do!

So there are two commands you need to know - pbcopy and pbpaste. You can use them together with the pipe operator | and the "to file" operator > to do really cool stuff.

Here's a few examples:

To paste whatever is in your clipboard into a new file - let's say .env - you can do this:

$ pbpaste > .env
Enter fullscreen mode Exit fullscreen mode

No more creating a new file, then opening it in vim or VSCode to paste and save - now you can just type a few characters and get the job done!

Similarly, if you want to copy a file to the clipboard, you use the pipe operator and pbcopy. This is how it looks:

$ cat .env | pbcopy
Enter fullscreen mode Exit fullscreen mode

cat echoes out the entire contents of a file (in this instance .env) and the pipe operator passes it as input to the pbcopy command. Voilá - now you can copy the content of entire files without opening them!

I use this all the time when I need to copy my ssh key and paste it into GitHub or BitBucket.

You don't have to limit yourself to files though - pbcopy is much more flexible than that. Whatever you pipe in can be placed on the clipboard - so if you want to copy the result of a program (let's say an encryption program or pwd), you just pipe it on in.

Doing more with less

I often use the tiny file reader program less to scan, search and read through files. It's really powerful if you know how to use it, but even if you're just using it for the first time, you can just use the arrow keys on your keyboard to scroll through files directly in the terminal.

Now, I use this mostly to read configuration files, and if I come across something I need to change, I've always had to close the file I was looking at, and open it in an editor like vim.

Luckily - you can just type v, and the default editor (typically vim) opens up, focused on the same line you were at. Once you close vim (provided you know how to close vim), you're placed back in the same spot as you were as well.

Also - you can go the start of the document with g, and to the end with shift+g. You can search for a phrase by tapping /, and typing out whatever you're looking for. Navigate through the occurrences by n (forward) and shift+n (backwards). And there's a ton of other things you can do (which you can read about here).

Open files and folders with open

Often times, you stumble across a file you want want to open the file's default application. That might be a video, an audio clip or perhaps a CSV file. You could exit the flow you're in, of course, and use Finder to navigate to your file and double click it - but we can do better.

If you want to open any file, you can use the open command to get it done from the terminal:

$ open videos/screen_recording.mp4
$ open package.json
$ open images/vacation.png
Enter fullscreen mode Exit fullscreen mode

I usually don't open a lot of files this way, but I do open folders! Just use open on any folder, and you'll get started right away!

$ open ~/Documents
$ open . # opens the current folder
Enter fullscreen mode Exit fullscreen mode

Some power characters!-

There are two really nice characters to know when using the terminal, and those two are - and !.

The - character (dash, hyphen, whatever you call it) works well in two contexts. You can add it to the cd command to return to the previous directory you were in, and you can add it to git checkout to check out the previous branch you were on.

# Example of using cd -
~/Documents $ cd /usr/bin
/usr/bin $ cd -
~/Documents $

# Example of using git checkout -
(master) $ git checkout feature-branch
(feature-branch) $ git checkout -
(master) $
Enter fullscreen mode Exit fullscreen mode

The exclamation mark is also pretty neat - it lets you search the history of command you've done previously, or re-use the arguments to the last command you used.

$ !cat
$ # shows you the last command you ran that started with cat

$ less a.txt b.txt
$ vim !* # opens a.txt and b.txt in vim

$ less a.txt b.txt
$ vim !$ # opens b.txt in vim
Enter fullscreen mode Exit fullscreen mode

It's a neat little trick that I know for some reason, but I never use. Perhaps you'll find some use for it though!

Much more usable, however is the double exclamation point! Especially in conjunction with the sudo command. If you've ever run a command and realized you had to run it as an administrator, you can simply do sudo !! and re-run it with sudo!

$ chmod +x /usr/share/firmlinks
chmod: Unable to change file mode on /usr/share/firmlinks: Operation not permitted
$ sudo !!
$ # Now it works!
Enter fullscreen mode Exit fullscreen mode

Searching the command history

Speaking of command history - you don't really need the ! command when you know about the ctrl+r shortcut! Tap it once, and you'll be able to do an interactive autocomplete search of your entire command history!

Oh my...

Lastly, I want to talk about oh-my-zsh. Zsh (pronounced sea shell) is a popular alternative to the well known bash shell, and oh-my-zsh is a small framework that adds a ton of useful functionality, aliases and plugins to make your workflow as smooth as possible.

If you haven't installed it already, you can do so by visiting their home page. Next, pop up this cheat sheet and start learning. There's a ton of useful shortcuts for git (like gst for git status and gc for git commit), but also really nifty commands like ... for navigating two directories up or take deep/directory/tree for creating a new directory and navigating into it.

In addition, there are tons of great themes and plugins available to make your terminal super powerful. I've had oh-my-zsh installed for years, and I just love it more for every passing day.

Last words

These are some of my favorite tips for being productive in the terminal. There are tons of stuff I've skipped - like how to grep or exit vim - but to be honest I don't use those a lot either. I hope you found at least one new technique to add to your roster - and that you promise to share your favorite commands with your fellow readers in the comments section.

Comments 6 total

  • Hacı DAYI
    Hacı DAYIJul 5, 2020

    Great tips. Specially !! :)
    Thanks

  • David Romero
    David RomeroJul 6, 2020

    And always remember if you forget something, use ... man [command]

  • Samuel Abreu
    Samuel AbreuJul 6, 2020

    About the clipboard, it is possible to use shift+insert to paste and Ctrl+insert to copy.

  • Firoz Ansari
    Firoz AnsariJul 6, 2020

    My heart skips a beat reading your title "Terminal illness" 😧

  • Gustin Alison
    Gustin AlisonSep 26, 2025

    My daughter was diagnosed with Epilepsy. The neurologist was very confident about the diagnosis . My Daughter had an EEG (no idea if it showed anything; we were tired and may have misunderstood what he said about that). MRI was negative for problems. For the past 4 months or so, I have seen weekly occurrences, making strange faces (this involved cheek twitching and lip quivering). We did not realize it could be a serious problem until she had an obvious seizure (simple partial) last week. What is troubling about my daughter's condition is that we have seen many daytime seizures, and that recently the seizures seem to cluster together. No idea if there are seizures occurring at night.We were given a prescription for Kapra, but are still weighing the risk / rewards of giving the medication to a toddler. After returning from the hospital, my daughter experienced a round of vomiting lasting from 3 AM to 11 AM, followed by additional vomiting the following morning at around 2 AM. Nothing makes sense then. She has not had an appetite, is drinking fine, and otherwise appears healthy. I read a lot of blogs where people who shared their testimonies kept mentioning Anti-seizure Herbal medication. I searched for a website called Herbalife cure. I just followed the email address of Doctor Joseph that was shared on these testimonies; I got lucky when I got a reply from Dr. Joseph. I followed his instruction, used Herbal Medicine in less than 2 months, and my daughter's seizures reduced drastically. Within a period of 5 months, my daughter was cured. I went back to my neurologist, where my daughter checked up and marked epilepsy free. contact him via email : joseph.healinghome@gmail.com. or whatsApp at wa.me/2347059186346

  • Gustin Alison
    Gustin AlisonSep 26, 2025

    I thought that they would never stop I was afraid to leave my house in fear of having one out in public I would have an aura before hand that I started uncontrollably looking up at the ceiling and falling backwards felt like that feeling when you go down a roller coaster only it wasn't a good feeling to me. While I was unconscious having the seizures every time I would see myself on an ambulance and I was dying from the seizure which made me panic every time I woke up on an actual ambulance after a seizure I would flip out on the paramedics and demand they let me out I was still out of it but I was panicking because I thought I was going to die. Eventually in 2019 I told my doctor that dilantin did nothing for my seizures but make them worse so he put me on Keppra 500 mg two times a day and I got off the dilantin, I used for a year plus nut noting works out not until I found Dr. Joseph who sent me some herbal medicines and directed me how to use, since doing so I have not had a seizure in almost dr Joseph.healinghome@gmail.com or via WhatsApp wa.me/2347059186346

Add comment