The world’s leading publication for data science, AI, and ML professionals.

5 Terminal Commands That Make Your Life A Little Easier.

When I was first introduced to the command line on my computer, it seemed confusing, and low-tech…

When I was first introduced to the command line on my computer, it seemed confusing, and low-tech. It brought me back to my days as a teenager, punching codes into an old-school POS system, or checking inventory in an outdated company intranet. Though these technologies looked dated, they were functional. As I became more comfortable with the Terminal I quickly realized that it was far more than functional, it exposed a host of small programs that you could use to interact with the computer, solve problems, and even chain together in complex ways. The following is a breakdown of some of the programs I find myself using most often.

htop

Unix machines ship with the built-in command line program top which allows you to see a real-time breakdown of the processes currently running on your system. It’s a classic program, released in 1984. In 2004, Hisham Muhammad released htop (the h refers to his first initial) which is similar to top but with a nicer user interface and some additional functionality. With htop you can scroll horizontally and vertically, view processes in different formats (for example, a tree view) and the user interface has a color output, which may seem trivial but helps immensely with readability. The only downside is that htop does not come pre-installed on your machine and needs to be downloaded using the following command:

apt-get install -y htop

Or using brew on a Mac

brew install htop

tree

The tree command comes pre-installed on Linux and is a handy tool I find myself using often when writing documentation for project repositories. It recursively traverses the filesystem from the folder where the command is ran. So if you typed tree in your base ~ filesystem folder, then the command would walk the entire filepath, displaying folders and filenames as it went. This command requires installation on a Mac:

brew install tree 

Here is an example of the output when it is ran within a small folder:

wikit

The amount of time I spend opening a browser window, navigating to Wikipedia, and performing a search is immense. But sometimes, I only really want to read the small summary intro paragraph. Wikit is a command line utility for linux which returns the introductory paragraph of a wikipedia article. Whenever I’m using linux, I like having that quick access to look things up.

locate

As the name suggests, locate searches the filesystem for a searched term and returns the full path to the result(s). I find myself using this a lot because it’s much faster than clicking around folders looking for things, and if it returns multiple outputs, you can pipe it into grep in order to refine the search.

Let’s say I want to find all the files with the word ‘medicare’ and I know that they must be in a specific folder (or in my case, on a removable volume). I can use the following syntax to filter the results returned by locate :

locate medicare | grep -i volumes
------
locate [file search term]| grep -i [folder]

caffeinate

One of the most useful commands on the list, caffeinate keeps your computer awake. There are many GUI programs on the market that achieve this same goal, but with caffeinate you can do things like keep your computer awake while a particular process is running, then stop preventing your computer from sleeping. The following commands keeps my computer awake for 100 seconds.

This command is available on both Mac and Linux computers, and is especially useful for things like model training or web scraping, where you might have a process run overnight.

Hopefully, you learned about a few new commands that you can now deploy in your day-to-day. Feel free to comment below with your favorite command line programs!

Happy coding 🙂

Check out my website!


Related Articles