Terminal Navigation and File Operations
15 min · Beginner
Need help? Ask a tutor on WhatsApp (opens in a new tab)Showing steps for Windows. They are marked “On Windows” below.
The terminal is a text window where you type commands instead of clicking. Developers use it to run programs, install packages and start virtual environments. On Windows you will use PowerShell; on a Mac you will use Terminal, which runs zsh.
Working Directory and Navigation
The working directory is the folder your terminal is currently inside. Commands that use a relative path, such as src/main.py, start looking from this folder.
Your terminal always sits inside one folder. Check where you are, list what is there, then move. Relative paths start from this folder; absolute paths start from the root of the disk.
On Windows
In PowerShell, pwd prints the folder, dir lists it, and cd .. moves up one level. Absolute paths start with a drive letter such as C:\.
PS C:\Users\Priya> pwdPS C:\Users\Priya> dirPS C:\Users\Priya> cd shop-appPS C:\Users\Priya> cd ..OutputPath ---- C:\Users\Priya Directory: C:\Users\Priya Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 03-11-2026 09:10 shop-app
Creating and Inspecting Files
You can make folders and files without opening a file manager. Create a folder called src, put an empty main.py inside it, then print the file.
On Windows
PowerShell uses mkdir for folders and New-Item for files. Get-Content prints a file (the short name cat also works). An empty file prints nothing.
PS C:\Users\Priya\shop-app> mkdir srcPS C:\Users\Priya\shop-app> New-Item src\main.py -ItemType FilePS C:\Users\Priya\shop-app> Get-Content src\main.pyOutput Directory: C:\Users\Priya\shop-app\src Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 03-11-2026 09:14 0 main.py
Running Python Scripts from CLI
To run a script, give its path to the Python program. The path is checked from your working directory. Assume src/main.py holds the sys.argv program from the next section; it prints the script name.
On Windows
Windows installs the py launcher with Python, so py always works. python works too if you ticked "Add python.exe to PATH" in the installer. Folders use a backslash.
PS C:\Users\Priya\shop-app> py src\main.pyPS C:\Users\Priya\shop-app> python src\main.pyOutputScript name: src\main.py Script name: src\main.py
Inspecting sys.argv in Python
A command-line argument is a word typed after the script name, such as hello in python app.py hello. Python collects these words in sys.argv as strings.
Python makes CLI arguments available in the sys module as a list of strings.
import sys
print(f"Script name: {sys.argv[0]}")if len(sys.argv) > 1: print(f"First argument: {sys.argv[1]}")sys.argv[0] is always the script name or path. Arguments passed after the script name populate indices 1, 2, and beyond.
Example
import sys
args = sys.argv[1:]print(f"Received {len(args)} argument(s)")for i, arg in enumerate(args, start=1): print(f"Arg {i}: {arg}")Received 0 argument(s)
What this code does
sys.argv[1:]slices off the script path, keeping only user-passed parameters.- When run without extra arguments, the slice is empty
[]. - Passing
python app.py hello worldwould print 2 arguments.
Next step
Check your understanding
7 quick questions