Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

The terminal - Practical Go Lessons https://www.practical-go-lessons.

com/chap-3-the-terminal

Chapter 3: The terminal

1 What will you learn in this chapter?


• What are a shell, bash, and a terminal?

• How to launch a terminal application?

• How to issue basics commands with bash?

• How to improve your “developer experience” on Windows?

1.1 Technical concepts covered


• GUI: Graphical User Interface

• CLI: Command Line Interface

• Shell

• Bash

• WSL: Windows Subsystem For Linux

2 Introduction
The day-to-day life of a Go programmer requires the usage of the terminal. This chapter will explain what the terminal is and how to use it. If
you are already familiar with it, you can skip the chapter.

3 Graphical User Interface (GUI)


Operating systems like macOS, Windows, or Linux offer a rich graphical user interfaces (GUI). To launch a program installed on your
computer, you generally double-click on an icon placed on your desktop. Programs will be displayed in windows with an interactive interface:
menus, sidebars, buttons...

We say that those programs offer a graphical user interface (GUI). The vast majority of users will use programs that provide these interfaces.
Graphical interfaces are easy to use and intuitive.

The paper and the digital edition of this book are available here. ×
I also filmed a video course to build a real world project with Go.

4 Command Line Interface (CLI)


Graphical user interfaces have not always existed. The first computers did not have such capability. But how do the users of those computers
managed to launch and use programs? Computers were shipped with a command-line interface. This interface is also called a “shell”. A shell

1 of 7 02/01/2023, 02:00
The terminal - Practical Go Lessons https://www.practical-go-lessons.com/chap-3-the-terminal

is a program that can pass commands to an operating system1. Shell is a generic term that designates such programs. The most famous shell
is bash (Bourne Again Shell). Bash is shipped by default with macOS and a vast majority of Linux Distributions. Windows is also shipped by
default with a shell (but it’s not bash).

5 How to interact with a shell: the terminal


The shell was presented to the user directly after startup on old computers. On modern computers, we have to launch a program to interact
with a shell. This program is often called a terminal. We will see how to open a terminal with MacOs, Linux (GNOME), and Windows.

5.1 macOS
• Open the Finder application :

Finder Icon

• Then on the menu bar, click on “Go” and then “Utilities”

Utilities

• A window will open. Click on “Terminal”

Terminal Application

• A new terminal will open

2 of 7 02/01/2023, 02:00
The terminal - Practical Go Lessons https://www.practical-go-lessons.com/chap-3-the-terminal

Terminal Application

Note that I use a customized terminal. Thus you might see a different output; this is perfectly normal.

5.2 Linux (Ubuntu)


• On Ubuntu, you can use the shortcut Ctrl+Alt+T

• You can also launch the terminal with the Ubuntu Dash. Type “Terminal” and the application should appear.

5.3 Windows
• Click on the start button, then in the text box type “cmd” (for command prompt)

3 of 7 02/01/2023, 02:00
The terminal - Practical Go Lessons https://www.practical-go-lessons.com/chap-3-the-terminal

Search for cmd application

• Then click on the application cmd.

Open cmd application on Windows

• A black window should appear; this is your terminal!

Windows terminal

5.3.1 Cmder
The terminal and the Windows shell is not very practical on a day today basis. I advise you to install cmder2 To make your developer life
easier on windows. Cmder is an emulator that will allow you to use commands available on Linux/MacOS. The installation process is easy
(download the latest release on GitHub) then launch the installation wizard.

After installing cmder, launch the program “Cmder” to open your brand new terminal.

5.3.2 Bash for Windows

4 of 7 02/01/2023, 02:00
The terminal - Practical Go Lessons https://www.practical-go-lessons.com/chap-3-the-terminal

By default, you cannot use bash on a Windows computer. This is not a problem, but it means that you will have to find the Windows
equivalent for each macOS/Linux command. It can be cumbersome at some point because a lot of examples and tutorials on the web do not
always provide equivalence for Windows.

Microsoft announced that you can now install a “Windows Subsystem for Linux” (WSL) on your Windows computer. This is a piece of good
news because you will use bash. You can find the installation instructions on the Microsoft website: https://docs.microsoft.com/en-
us/windows/wsl/install-win10 (for Windows 10).

I strongly advise you to install this, because it will make your life easier even if I try to give Windows equivalent for basic commands in the
next sections.

6 How to use the terminal


After you opened your terminal, you will see a black window. This is the interface where you can type commands. This is not intuitive because
to type commands; you have to know them before! Each command has a name. To launch a command, you will type its name, eventually type
some options and then press enter. Let’s take an example.

6.1 About the dollar symbol


In the examples, you will see a line that begins with a dollar symbol. This is a convention; it means “type it into your terminal”, when you want
to reproduce the examples do not type the dollar, just everything after it.

6.2 MacOS / Linux


Let’s say we want to list the contents of your desktop. Type the following command (replace maximilienandile by your name).

• For macOS

$ ls /Users/maximilienandile/Desktop

• For Linux

$ ls /home/maximilienandile/Desktop

Then press enter. You will see a list of files and directories.

Now type the following command :

$ pwd

Press enter. The result is the following :

/Users/maximilienandile

Here we used two commands :

• ls: allow you to list the contents of a directory

• pwd: allow you to print the working directory, (print the name of the directory you are into)

6.3 Windows (without Linux for windows)


The command to list the contents of the current directory is dir :

5 of 7 02/01/2023, 02:00
The terminal - Practical Go Lessons https://www.practical-go-lessons.com/chap-3-the-terminal

Windows terminal

Each line will represent either a file or a directory. There are “<DIR>” In the third column, if it’s a directory. Nothing if it’s a file.

6.4 Windows (with WSL & Cmder)


If you have installed WSL and cmder, the first step is to launch cmder (via the windows menu, for example). Then you can launch bash by
typing this command :

$ bash

And press enter. Now you are using bash! (congratulations). To list elements in your home directory, simply type :

$ ls /mnt/c/Users/maxou123

(where maxou123 is your username).

7 Test yourself
7.1 Questions
1. What is the command to list the contents of a directory?

2. What is a terminal?

3. Give the name of a well-known shell.

7.2 Answers
1. What is the command to list the contents of a directory?

1. ls (for UNIX sytems)

2. dir for Windows

2. What is a terminal?

1. A terminal is a program that offers an interface to use a shell


3. Give the name of a well-known shell.

1. bash

The paper and the digital edition of this book are available here. ×
I also filmed a video course to build a real world project with Go.

8 Key takeaways
• Graphical User Interfaces have not always existed

• To interact with computers, we can use a Graphical Interface or a Command line Interface. (CLI)

6 of 7 02/01/2023, 02:00
The terminal - Practical Go Lessons https://www.practical-go-lessons.com/chap-3-the-terminal

• To use a CLI, we have to open a terminal application that offers an interface to interact with a shell

• Bash is a shell.

• You can launch commands by typing the command name and eventually options, then press enter.

• We will use the terminal to launch go-specific commands.

1. http://www.catb.org/jargon/html/S/shell.html↩

2. https://cmder.net/ , github repository : https://github.com/cmderdev/cmder↩

Bibliography
Previous Next

The Go Language Setup your dev environment

Table of contents

Did you spot an error ? Want to give me feedback ? Here is the feedback page! ×

Newsletter:
Like what you read ? Subscribe to the newsletter.

I will keep you informed about the book updates.

@ my@email.com

Practical Go Lessons
By Maximilien Andile
Copyright (c) 2023
Follow me Contents
Posts
Book
Support the author Video Tutorial

About
The author
Legal Notice
Feedback
Buy paper or digital copy
Terms and Conditions

7 of 7 02/01/2023, 02:00

You might also like