DEV Community

Cover image for A Guide To Loving Your Terminal
Lazar
Lazar

Posted on

A Guide To Loving Your Terminal

*Congratulations, you are a proud terminal owner! *

When I first switched to Linux, I avoided my terminal like the plague. Now I don't know how I managed without my terminal!

But I think there is a lot more we can do to just make our experience easier.

Write Shell Scripts

Say you have a long list of commands you need to run, but now enough time to sit there waiting typing them all out one at a time. A simple shell script can solve that problem! But shell scripts go beyond just commands.

Since I use Bash. I am going to focus on Bash. A few people don't realize that Bash is a full featured scripting language. It has while loops, if statements, takes input, and does basically anything that any other scripting language can do. This can be really great for making things automated on your computer. It is also really easy to get shell scripts to start running on startup, which is perfect if you wan't it running in the background.

I have a joke that I already built AI by myself because of the amount of shell scripts I have running at one time.

Use the '&&' operator

The && operator is what turns two terminal commands into one. For example:

echo "hello" && echo "Lazar"
Enter fullscreen mode Exit fullscreen mode

This just prints out in the terminal:

"hello"
"Lazar"
Enter fullscreen mode Exit fullscreen mode

Word for the wise here this is NOT concatenation! It runs the two commands separately, that's why it printed on two different lines.

So what can you do with this, plenty It really saves time for me. When I used to use Debian, and I was installing something it would sometimes take a really long time for the repositories to update, then I would have to go still and type the command to install something. So I would just type:

sudo apt-get update && sudo apt install
Enter fullscreen mode Exit fullscreen mode

Change the terminal font

Comment down below, if you change the font on your terminal. Because I don't know ANYONE who does. Now, I can't comment on every terminal out there, but for gnome, deepin and tilix, it is really easy. ** Preferences => General => Font**. I find if you wanna make the terminal just a little less scary, just use a font that maybe is a little more calming for you. Also, In deepin, you can change the theme and the opacity of the terminal.

So that's all for now. I think I may have to write a few of these articles like this, this week because I am working on two different projects for two different people and really can't work on anything spectacular right now.

Y'all have a great day!

Top comments (13)

Collapse
 
mitchartemis profile image
Mitch Stanley

Another bonus for the && syntax is that if the first command fails it will not run the second command.

This is useful if the second command relies on the first commands result (Like with your example updating packages).

If they're two separate commands that don't rely on each other then you can use ; instead.

Collapse
 
samuelabreu profile image
Samuel Abreu

Also || is a valuable tool on scripts, to exit or inform an error:

do_something_amazing || echo “nope” && exit 1

Collapse
 
mithil467 profile image
Mithil Poojary

I use that with gcc.
gcc filename.c && ./a.out

If compilation failed, it won't run the program.

Collapse
 
bootcode profile image
Robin Palotai

+1: commit your dotfiles to a repo so it's easy to restore on an other machine.

Eventually I would like to write about the collection of terminal tools I use and love (like grep, sed, tmux, multitail, ncdu, ranger etc). Follow me if you want to read one day.

Collapse
 
skydevht profile image
Holy-Elie Scaïde

I pretty spend my coding life between the terminal and the browser (which is the only things keeping me from going full minimal). I use Neovim as a text editor and even if you can launch commands within it, it' often faster for me to pause it using ctrl-z and resume it afterward with fg. I usually have both Ranger and Neovim open and I can be pretty fast with them (keyboard only). Another thing that helps is using zsh and oh-my-zsh with a few plugins enabled (git, yarn, laravel5, z) which boost my productivity to the roof

Collapse
 
maxdevjs profile image
maxdevjs

Once I found a fancy function to handle ctrl-z behaviour. As seems that you use zsh and in a similar way, here it is:

fancy-ctrl-z () {
  if [[ $#BUFFER -eq 0 ]]; then
    BUFFER="fg"
    zle accept-line
  else
    zle push-input
    zle clear-screen
  fi
}
zle -N fancy-ctrl-z
bindkey '^Z' fancy-ctrl-z
Collapse
 
lazar profile image
Lazar

Funny you talk about going full minimal! Same thing with me, the browser is the only one tying me down as well... or else I would just have a full cli system. lol

Collapse
 
vitalcog profile image
Chad Windham

+1 for changing terminal font lol, whenever I set up a computer the first thing I do is change the default size of my terminal (making it much bigger), increase the font size to make things easier to read, and change the font (for the same reason)

Collapse
 
scorp13 profile image
scorp13

A couple of years ago I wrote a small cheat sheet on some terminal commands for myself

Collapse
 
cycolucas profile image
Lvcäs

Amazing post!

Another very useful command is "man"! When you have no idea about all the capabilities of a certain program it shows the manual of it.

Collapse
 
maydev profile image
Mayank Yadav

+1 Set the background color to translucent, so you can see what's happening at the window beneath it.
+1 install 'nautilus', helps you open the terminal from any folder location.

Collapse
 
tuvannguyen profile image
Tu Van Nguyen

Yup, being able to use the terminal is like a super power for productivity. And it's amazing how many other tools you can suddenly use once you master the terminal.

Collapse
 
notsag profile image
Maxime Gaston

Actually, nearly anyone using ohmyzsh with a powerline font theme changed his terminal fonts 😉