5 Terminal Tricks to Improve Your Console Workflow
5 Terminal Tricks to Improve Your Console Workflow

I am already using terminal more than 10 years. This is why in this post I want to share with you 5 tips, that I am using with terminal every day, and they are really efficient.

And just a disclaimer here all these tips are for normal terminals, which means they will work out of the box in Linux and MacOS and in Windows you will have problems. It won’t work by default inside Windows console, but if you will install a console like Cmder or GitBash then it will also work there.

Ctrl + R

And my first tip is a keybind: ctrl+R. And a lot of people don’t know about such a keybind. So actually here I am inside terminal and when I am just hitting ctrl+R as you can see I am getting here a list of previous used commands.

Ctrl + R

And this is extremely effective, when you want to search something. Because actually you just used some command and you don't remember how to write it. You can simply hit ctrl+R and search here. For example I don’t remember how I used some git command. I can write here git and then the name. As you can see it is working out of the box there, you don’t need to install anything. But by default you don't have a list of used commands. You are just in history mode to find a command. If you want to see a list you need to install additionally fzf.

Highlighting items

The next really nice command is actually a package. And I am talking here about the package, which is called exa. As you can see here this is the official repository and the main idea is that it replaces ls command. And if you don't know ls command is the command to show the list of files in current folder.

The main point is that by default this command is really not super useful, it is not highlight in a lot. You simply see your directories and you see your file names, this is it. But with this package you can see here it is fully coloured and this is how it looks inside my directory.

Exa

So here I see all files are highlighted in different colors. So it makes it much easier for you to understand what files you are looking for. And actually if I will write which ls you can see, that my ls command inside terminal is aliased to

exa -lha

Which actually means I can write in console exa and it will render the list of the files exactly in default variant. Like we see, when we are writing ls. But it is not comfortable for me, this is why I am writing here exa with attributes to get a list. And in this case it looks like a table, which is easier to read. And if you want to use exa, you can simply download it on your machine and then you have lots of display options. So I highly recommend you to use it if you want a better clients of your files inside current directory.

Git commands

My next recommendation is to leverage Git commands. Actually if you are using git probably you are using it from the console. And if you don't I highly recommend you to learn how to use git from console, because first of all it is the native way and sometimes it is faster and you will for sure know what you are doing.

The main problems is that all git commands by default are quite verbose. For example you need to write

git checkout someFile.js
git checkout someBranch

It takes lots of time. The same is for example when you are writing git push or maybe git pull. This is why we have aliases inside git. And you can do it in two different ways. First of all you can write alias is inside git itself. And people typically write something like

git co someFile.js
git co someBranch

In this case you are using it like checkout and it is totally fine for beginners, but you can make it even better. You can leverage usage of aliases is for example for ZSH or Bash in this case you don't need to write git checkout or git co but

gco someFile.js
gco someBranch

and it will be exactly the same.

The main point is if you are writing aliases for git, then you must always start them with word git and it doesn't make a lot of sense, because it takes time. If you are mixing aliases with git and with ZSH, then you can just make aliases in ZSH and still use git underneath, which is really efficient.

For example to create a new branch I am using

gnb foo

This is extremely efficient and I highly recommend you to write a lot of aliases for yourself if you are using git.

Jumping to previous Git branch

And actually one more cool thing inside git that I am using a lot is -. And not a lot of people know about it. So typically you are on some branch and you want to switch back to previous branch. How you can do it? Obviously I can write

git checkout master

It will work. But let’s say that your branch was really difficult to remember and instead you can just write here minus (-)

git checkout -

And we jump to the previous branch. Now I am writing this command again and I am inside foo branch again. And actually it is working by default with git.

Terminal aliases

My next recommendation is to use a lot of aliases for yourself inside console. For example you can make alias for grep just like I did.

// instead of
ps aux | grep mpd

// I write
grep mpd

In this case I don't need to remember all attributes of the command and I can use it in much easier way.

Core utilities

The next cool thing, that I can recommend you is core utilities. And if you don’t know what is this you can install on your machine a lot of utilities to the terminal. And actually I am not using a lot of them, just 3. I use aliases to copy, move and delete a file to get progress, output and confirmation in termilal.

As you can see here I have 3 aliases for moving file, removing file and coping file.

Core utils aliases

And actually here I wrote gmv and this is actually core utility’s package and here I am using interactive and verbose. And actually this is a really nice wrap because you have this interactive mode inside the console. For example if you are removing a file or replacing it you don't get any interaction from the console, you simply remove a file and this is it. And this is not cool because you can make a mistake and in this case the file is already removed.

Core utils

But with core utils I see here a progress and actually this is really nice I see what I’m coping and where. And if I am coping for example 10 files then I will see all these 10 files directly. Secondly if I am hitting again and coping this file again as you can see I’m getting a message. So this is an interactive console. I am getting here a message overwrite and this file already exists. And I can say here yes to overwrite this file. And the same goals with removing. I am writing here rm and then here I have a downloads file that I want to remove. Here I am asked a message if I really want to remove this file. I am hitting yes and we are done.

Navigation

One more thing that we are using a lot inside console is obviously navigation. And typically you need to write

cd someFolder

And then we want to go out and we are write

cd ../..

And actually it all takes time. This is why here as you can see I have aliases with dots to go outside to the parent directory.

Navigation

And actually this is extremely efficient because in this case I am jumping to tasks and now I want to go up.

..

In this case I just put 2 dots and I am hitting enter. And I am inside parent directory. So it just saves time and you don't need to write cd every single time, when you want to go outside of the directory.

Bonus

And here is my bonus tip for you, which is working on Mac OS out of the box and it is called caffeinate. If you want to do something on your machine and your machine should not go to sleep then you can simply start

caffeinate

So you are just typing inside console caffeinate and you are hitting enter. And as you can see this process is hanging here. And actually it will prevent your machine to go to sleep. For example if you have some script running and you need your hard drive or something like that. And this is really nice, because you are getting this script out of the box, you don’t need to do anything you simply start it and you are good to go. Then if you don’t need it anymore and you want to stop it you simply hit ctrl+c and you are done.

I hope that my recommendations will help you to increase your productivity inside a terminal. And actually if you are interested in 7 books that I highly recommend to every single programmer make sure to check this post also.