The Desi Architect
Notes / Docker Sandboxes / Terminal Survival Kit
Track 06 · Docker Sandboxes · Reference

Terminal Survival Kit

The few terminal commands every lab uses, with Bash (Mac, Linux, Git Bash) and PowerShell (Windows) side by side. If you have never used a terminal, start here.

Free referenceKeep this tab open while you do a lab

00 /What a terminal is

In plain words

A terminal is a window where you type commands instead of clicking. The terminal always works "inside" one folder, the current folder. Commands that use files look there first.

Open one: on Windows search for PowerShell (or Git Bash if you installed Git). On a Mac open Terminal. On Linux, the keyboard shortcut is usually Ctrl+Alt+T.

01 /Moving around and looking at files

You want toBash (Mac, Linux, Git Bash)PowerShell (Windows)
Where am I?pwdGet-Location (or pwd)
List fileslsdir (or ls)
Go into a foldercd lab-foldercd lab-folder
Go up one foldercd ..cd ..
Make a foldermkdir mylabmkdir mylab
Show a filecat file.txttype file.txt (or cat)
Copy, move, delete a filecp a b, mv a b, rm aCopy-Item a b, Move-Item a b, Remove-Item a
Delete a folder and everything in itrm -rf folderRemove-Item -Recurse -Force folder
Careful with delete

There is no recycle bin. rm -rf and Remove-Item -Recurse -Force delete for good, and the folder name must be exactly right.

02 /Starting a lab

Which terminal are you using?
mkdir my-lab && cd my-lab
unzip ~/Downloads/my-lab.zip
ls
mkdir my-lab; cd my-lab
Expand-Archive -Path "$HOME/Downloads/my-lab.zip" -DestinationPath .
dir

Unzip every lab into its own new folder, then run all commands from inside that folder. Many "file not found" errors are only "I am in the wrong folder".

03 /Running scripts

You want toBashPowerShell
Run a script in this folder./test.sh.\test.ps1
Run Pythonpython3 file.pypython file.py (or py file.py)
Stop a running commandCtrl+CCtrl+C
Repeat the last commandUp arrow, EnterUp arrow, Enter
Clear the screenclearcls

If PowerShell refuses to run a .ps1 file, run it like this once: powershell -ExecutionPolicy Bypass -File .\test.ps1.

04 /Pipes, searching and saving output

You want toBashPowerShell
Send the output of one command into another (a pipe)docker ps | grep webdocker ps | Select-String web
Search a file for textgrep error app.logSelect-String error app.log
Show the first or last lineshead -20 f, tail -20 fGet-Content f -TotalCount 20, Get-Content f -Tail 20
Save output to a filedocker compose logs > logs.txtdocker compose logs > logs.txt
Count lineswc -l file(Get-Content file).Count

05 /Environment variables

You want toBashPowerShell
Set one for the current terminalexport REDIS_HOST=cache$env:REDIS_HOST = "cache"
Set one for a single commandREDIS_HOST=cache docker compose up -d$env:REDIS_HOST = "cache"; docker compose up -d; Remove-Item Env:REDIS_HOST
Read oneecho $REDIS_HOSTecho $env:REDIS_HOST

06 /Quotes and long lines

  • Bash: single quotes '...' keep the text exactly as typed. Double quotes "..." allow $variables.
  • PowerShell: the same idea, but when you pass JSON with double quotes to a program such as curl.exe, put a backslash before each inner quote: -d '{\"name\":\"asha\"}'.
  • Long lines: end the line with a backslash in Bash, and with a backtick in PowerShell, then continue on the next line.

07 /Three Windows traps

  • curl in PowerShell is a different command. Type curl.exe.
  • python3 on Windows may open the Microsoft Store. Use python or py.
  • In Git Bash, a path like /app inside a command can be rewritten to C:/Program Files/Git/app. Put MSYS_NO_PATHCONV=1 in front of the command, or use PowerShell.

More fixes are in the Windows Troubleshooting guide.