// tech tips · beginner
Command Line Basics for Beginners: Windows, Mac and Linux
Learn to use the terminal with confidence. Find where you are, move between folders, create and list files, and run Python scripts, with commands for Windows, Mac and Linux.
The command line (also called the terminal, console or shell) looks old-fashioned: a black window where you type instead of click. But it’s the quickest way to run programs, and nearly every coding tool, including Python, pip and Git, is used from it. You only need about ten commands to feel at home.
Opening a terminal
- Windows: press Start, type
PowerShellorcmdand press Enter. In VS Code, press Ctrl + ` to open one inside the editor. - Mac: press Cmd + Space, type
Terminaland press Enter. - Linux: press Ctrl + Alt + T on most systems.
You’ll see a prompt, a line ending in > or $, which shows the terminal is waiting for a command. Type a command and press Enter to run it.
Where am I?
The terminal is always “inside” one folder, called the current working directory. Many beginner problems, such as “No such file or directory”, happen because the terminal is in a different folder from your file.
pwd # Mac, Linux and PowerShell: print working directory
cd # Command Prompt (cmd) on Windows: shows the current folder
Your home folder is where you usually start, for example C:\Users\Ava on Windows or /Users/ava on a Mac.
What’s in this folder?
ls # Mac, Linux and PowerShell
dir # Windows (cmd and PowerShell)
Moving around with cd
cd means change directory:
cd Documents # go into a folder called Documents
cd coderunner # go further in
cd .. # go up one level (to the parent folder)
cd ~ # go to your home folder (Mac, Linux, PowerShell)
.. always means “the folder above this one”, and . means “this folder”.
If a folder name contains spaces, wrap it in quotes:
cd "My Projects"
Tip: type the first few letters of a name and press Tab. The terminal completes it for you, which is faster and avoids typos.
Creating folders and files
mkdir python-practice # make a new folder (all systems)
cd python-practice
To create an empty file:
touch hello.py # Mac and Linux
New-Item hello.py # Windows PowerShell
type nul > hello.py # Windows Command Prompt
Most of the time, though, you’ll create files in your code editor and use the terminal to run them.
Running Python scripts
Once you’re in the right folder, run a script like this (see your first program):
python hello.py # Windows
python3 hello.py # Mac and Linux
Typing python on its own opens the interactive shell, where you can try lines one at a time. Type exit() to leave it.
Copying, moving and deleting
| Task | Mac / Linux | Windows (cmd) | Windows (PowerShell) |
|---|---|---|---|
| copy a file | cp a.py b.py |
copy a.py b.py |
Copy-Item a.py b.py (or cp) |
| move or rename | mv a.py b.py |
move a.py b.py |
Move-Item a.py b.py (or mv) |
| delete a file | rm old.py |
del old.py |
Remove-Item old.py (or rm) |
| delete an empty folder | rmdir old |
rmdir old |
Remove-Item old |
Careful: files deleted from the terminal do not go to the Recycle Bin or Trash. They’re gone. Double-check the name before pressing Enter, and never run a delete command you’ve copied from the internet unless you understand exactly what it does.
Time-saving tricks
- ↑ / ↓ arrow keys scroll through commands you’ve already typed, so you rarely need to retype
python hello.py. - Tab completes file and folder names.
- Ctrl + C stops a running program, such as a loop that never ends.
cls(Windows) orclear(Mac, Linux, PowerShell) clears the screen.- Drag a folder from File Explorer or Finder onto the terminal window to paste its full path.
Opening a terminal in a specific folder
- Windows: open the folder in File Explorer, click the address bar, type
cmdand press Enter. Or right-click inside the folder and choose Open in Terminal. - Mac: right-click the folder in Finder and choose Services → New Terminal at Folder (you may need to turn this on in System Settings → Keyboard → Keyboard Shortcuts → Services).
- VS Code: open the folder with File → Open Folder; its built-in terminal starts there automatically (see Set Up VS Code).
Common messages and what they mean
| Message | Meaning | Fix |
|---|---|---|
'python' is not recognized… / command not found |
the program isn’t installed, or isn’t on your PATH | reinstall Python and tick Add python.exe to PATH; on a Mac try python3 |
No such file or directory / cannot find the path |
that file or folder isn’t where the terminal is looking | run ls or dir, then cd into the right folder |
Permission denied |
you’re not allowed to change that location | work inside your own home folder or Documents |
Practise: a five-minute workout
Try this sequence to build confidence:
cd ~
mkdir terminal-test
cd terminal-test
python -c "print('Hello from the terminal!')"
cd ..
On a Mac, use python3 instead of python. The -c option runs a line of Python straight from the command line. Then find terminal-test in File Explorer or Finder, and delete it there.
Key points
pwd(orcdin cmd) shows where you are;lsordirlists what’s there.cd foldergoes in,cd ..goes up, and Tab completes names.mkdirmakes folders;python file.pyruns scripts.- Use ↑ to repeat commands and Ctrl + C to stop a program.
- Terminal deletes are permanent, so be careful.
Now you can run code with confidence, learn to fix it when it misbehaves in Debugging Python in VS Code.