What Is the Terminal
Think of the terminal as a chat with the computer. Instead of clicking icons and menus, you type commands as text and the computer responds. Itβs like sending a WhatsApp message, but to your machine. You type "list the files," and it lists them. You type "create a folder," and it creates one.
π§ Analogy: The Terminal Is a Chat
Imagine you have an extremely obedient assistant. It doesnβt understand gestures or clicks. But if you write exactly what you want, it does it right away. That assistant is the terminal.
- β’You type: one command (e.g.,
ls) - β’It replies: the result (the list of files)
- β’You type it again: another command
- β’And so on. Each line is a "message".
π‘ Different names, same thing
Youβll hear several names: Terminal, Command Prompt, CMD, PowerShell, Shell, Console. They're all variations on the same idea: a text window for talking to the computer. On Mac and Linux, the most common is Terminal (with Bash or Zsh). On Windows, it's Command Prompt (CMD) or PowerShell.
Opening the Terminal on Your Computer
The first step is find and open the terminal. Each operating system has its own, but they all work the same way: you type, the computer responds.
Windows
Two terminals available: CMD (older) and PowerShell (modern)
# Option 1: Press the keys together
Windows + R, type "cmd", Enter
# Option 2: Start menu
Start Menu > type "PowerShell" > click
# Option 3: Right-click the folder
Shift + right-click > "Open command window here"
Recommendation: Use PowerShell. It accepts the same commands as CMD and more.
macOS
The Terminal comes preinstalled
# Option 1: Spotlight
Cmd + Space, type "Terminal", Enter
# Option 2: Finder
Applications > Utilities > Terminal
Linux
Terminal is built in and usually accessible with a keyboard shortcut
# Universal shortcut
Ctrl + Alt + T
# Or look in your apps
Menu > Terminal (or Konsole, GNOME Terminal)
π What youβll see when you open it
# On Mac/Linux, something like this:
user@my-computer ~ $
# On Windows CMD:
C:\Users\SeuNome>
# On Windows PowerShell:
PS C:\Users\SeuNome>
O $ (or > on Windows) and means the terminal is waiting for you to type. It's like a blinking cursor in a text box.
β οΈ Common Error
Problem: "I opened the terminal and it closed on its own."
Solution: This happens when you accidentally double-click a .bat or .sh file. The terminal opened using the methods above waits for your commands. If you closed it, open it again using your operating system's method.
Navigating Folders: cd, ls, pwd
In File Explorer, you click folders to open them. In the terminal, you do the same thing with commands. Think of the terminal as a blind file explorer: it only knows where it is if you ask, and only goes where you tell it.
pwd - Where am I?
"Print Working Directory". Shows the full path of your current location.
$ pwd
/home/usuario
On Windows, the equivalent is cd (without arguments).
ls - What's here?
"List". Lists all files and folders in the current directory.
$ ls
Desktop Documents Downloads Music Pictures
# In more detail:
$ ls -la
total 20
drwxr-xr-x 5 usuario usuario 4096 jun 16 10:00 .
drwxr-xr-x 3 root root 4096 jun 15 09:00 ..
drwxr-xr-x 2 usuario usuario 4096 jun 16 10:00 Desktop
-rw-r--r-- 1 usuario usuario 220 jun 15 09:00 .bashrc
In Windows CMD, the equivalent is dir. In PowerShell, ls it works.
cd - Go to another folder
"Change Directory". Changes to a different folder.
# Go to the Documents folder
$ cd Documents
$ pwd
/home/usuario/Documents
# Go up one folder
$ cd ..
$ pwd
/home/usuario
# Go straight to the home folder
$ cd ~
# Go to a specific path
$ cd /home/usuario/Documents/projetos
π‘ Tip: Tab autocomplete
When typing folder or file names, press the Tab to autocomplete. For example, type cd Doc and press Tab. The terminal completes it to cd Documents/. This prevents typos and saves time.
β What TO DO
- βUse
pwdwhenever you get lost - βUse Tab to autocomplete names
- βUse
cd ..to go back
β What NOT to do
- βType long paths without using Tab
- βIgnore error messages ("No such file")
- βUse spaces in folder names (complicates everything)
Creating and Manipulating Files
Now that you know how to navigate folders, itβs time to create, copy, move, and delete things. In the file explorer, you right-click > "New Folder." In the terminal, you type a command and that's it.
mkdir - Create a folder
# Create a folder named "meu-projeto"
$ mkdir meu-projeto
$ ls
meu-projeto
# Create nested folders all at once
$ mkdir -p meu-projeto/src/componentes
touch - Create an empty file
# Create a file named "index.html"
$ touch index.html
$ ls
index.html
# Create several files at once
$ touch index.html style.css script.js
On Windows, use echo. > index.html or New-Item index.html in PowerShell.
Copy, Move, and Delete
# cp = copy (source, destination)
$ cp index.html backup.html
# mv = move (also used to rename)
$ mv backup.html pasta-backup/
$ mv arquivo-velho.txt arquivo-novo.txt
# rm = remove (CAUTION: it doesn't go to the trash!)
$ rm arquivo-inutil.txt
# rm -r = remove a folder and everything inside it
$ rm -r pasta-antiga
β οΈ BE CAREFUL with rm
The command rm deletes permanently. Thereβs no trash can, no Ctrl+Z. Before you run rm -r, check three times that the path is correct. Never run rm -rf / (this deletes EVERYTHING on the computer).
mkdir
Create a folder
touch
Create a file
cp / mv
Copy / Move
rm
Delete (be careful!)
Editors: nano and VS Code
Creating an empty file is easy. But how do you add content to it? You have two options: edit directly in the terminal (with nano) or open it in a visual editor (such as VS Code). Both approaches work. The choice depends on the situation.
π nano: Editor inside the terminal
# Open or create a file with nano
$ nano index.html
nano opens inside the terminal itself. You type as usual. The shortcuts appear at the bottom:
GNU nano 7.2 index.html
<html>
<body>Hello world</body>
</html>
^O Save ^X Exit ^K Cut ^U Paste
^O = Ctrl+O (save) | ^X = Ctrl+X (exit) | The ^ means the Ctrl key.
VS Code: Visual editor accessed through the terminal
If you have VS Code installed, you can open any file or folder directly from the terminal:
# Open a specific file in VS Code
$ code index.html
# Open the entire folder as a project
$ code .
The point . means βcurrent folder.β This is the most common way to open projects in VS Code.
β Use nano when
- βNeed to edit something quickly (1β2 lines)
- βItβs on a remote server (SSH)
- βNeed to edit configuration files
π» Use VS Code when
- βYouβll work on an entire project
- βWant syntax highlighting (colors in the code)
- βWant autocomplete and extensions
Exercise: Build Your First Project
Time to practice everything together. Youβll create the web project folder structure using only the terminal. By the end, you'll have a folder and file structure ready to start coding.
π― What you'll build
meu-site/
βββ index.html
βββ style.css
βββ script.js
βββ img/
β βββ logo.png
βββ pages/
βββ sobre.html
βββ contato.html
Step 1: Create the project folder
$ mkdir meu-site
$ cd meu-site
$ pwd
/home/usuario/meu-site
Step 2: Create the root files
$ touch index.html style.css script.js
$ ls
index.html script.js style.css
Step 3: Create the subfolders and their files
$ mkdir img pages
$ touch img/logo.png
$ touch pages/sobre.html pages/contato.html
Step 4: Check the structure
$ ls -R
.:
img index.html pages script.js style.css
./img:
logo.png
./pages:
contato.html sobre.html
Step 5: Add content to index.html
$ nano index.html
# Type this inside nano:
<!DOCTYPE html>
<html>
<head><title>My Site</title></head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
# Press Ctrl+O to save, Enter, then Ctrl+X to exit
π Congratulations!
If you managed to create this entire structure without leaving the terminal, youβve mastered the fundamental commands. From now on, youβll use these same commands in every upcoming module. In the next one, youβll learn how to save versions of your work with Git.
π Module Summary
Next Module:
1.2 - Git: Saving Your Work (version control, never lose code again)