How to Change Directory at Command Prompt (Windows, Mac & Linux)
Navigating your file system through a command-line interface is one of the most fundamental computing skills you can develop. Whether you're on Windows Command Prompt, PowerShell, macOS Terminal, or a Linux shell, the ability to move between directories quickly and accurately unlocks everything from running scripts to managing files and troubleshooting software.
What "Changing Directory" Actually Means
Your operating system organizes files in a hierarchical tree structure. At the top sits the root directory — C: on Windows or / on Unix-based systems. Every folder (directory) branches outward from there.
When you open a command prompt, you start in a working directory — usually your user home folder. Every command you run executes relative to that location unless you specify otherwise. Changing the directory means telling the shell: "Move my working location to this other folder so my commands apply there."
The Core Command: cd
The command is cd, short for change directory. It works across Windows Command Prompt, PowerShell, macOS Terminal, and Linux Bash — though with some important differences in syntax.
Basic Syntax
cd [path] You replace [path] with either an absolute path (the full address from root) or a relative path (a location relative to where you currently are).
Absolute vs. Relative Paths
Understanding this distinction is critical before anything else.
| Path Type | Description | Example (Windows) | Example (Mac/Linux) |
|---|---|---|---|
| Absolute | Full path from root | cd C:UsersJohnDocuments | cd /home/john/documents |
| Relative | Path from current location | cd DocumentsProjects | cd documents/projects |
| Parent directory | Go up one level | cd .. | cd .. |
| Root directory | Go straight to root | cd | cd / |
| Home directory | Go to user home | cd %USERPROFILE% | cd ~ |
Absolute paths always work, regardless of where you currently are. Relative paths depend entirely on your current location, so they're faster to type but require awareness of where you are.
How to Change Directory on Windows Command Prompt
Open Command Prompt by pressing Win + R, typing cmd, and pressing Enter.
Move into a subfolder:
cd Documents Move into a nested folder using a full path:
cd C:UsersYourNameDocumentsProjects Go up one level:
cd .. Go up two levels:
cd .... Switch to a different drive (e.g., from C: to D:) — this requires a separate step in classic Command Prompt:
D: Then use cd normally on that drive. In PowerShell, you can navigate across drives directly with cd D:FolderName without this extra step — a meaningful difference if you work with multiple drives regularly.
Check your current location at any time:
cd Typed alone with no arguments, cd on Windows simply prints your current directory.
💡 How to Change Directory on macOS and Linux Terminal
The syntax is nearly identical, but the path structure uses forward slashes instead of backslashes, and the root is / rather than a drive letter.
Navigate to a folder:
cd /Users/yourname/Documents Use the shortcut for your home directory:
cd ~ Go up one level:
cd .. Check your current location:
pwd (pwd stands for print working directory — the Unix equivalent of typing cd alone in Windows.)
Handling Spaces and Special Characters in Path Names
Folder names with spaces cause errors if you don't account for them. A path like My Documents will break a basic cd command.
On Windows, wrap the path in quotes:
cd "C:UsersYourNameMy Documents" On Mac/Linux, either use quotes or escape the space with a backslash:
cd "My Documents" cd My Documents This is a common stumbling point for new command-line users and one worth memorizing early.
Useful Shortcuts That Speed Things Up
- Tab completion — Start typing a folder name and press Tab. The shell will auto-complete it if the folder exists. This works on Windows (Command Prompt and PowerShell), macOS, and Linux.
cd -on Mac/Linux — Returns you to the previous directory you were in, useful for toggling between two locations.- Drag-and-drop a folder into Terminal (Mac) — macOS Terminal lets you drag a folder from Finder directly into the terminal window, which pastes the full path automatically.
⚙️ Variables That Affect Your Experience
Several factors shape how straightforward (or complicated) directory navigation becomes in practice:
Operating system is the most significant variable. Windows uses backslashes and drive letters; Mac and Linux use forward slashes and a unified root. Users switching between systems often trip on this difference.
Shell type matters on Windows in particular. Classic Command Prompt, PowerShell, and Windows Subsystem for Linux (WSL) each behave differently — PowerShell and WSL both support more Unix-style behavior, which can simplify things for users familiar with Mac or Linux environments.
Directory depth and naming conventions affect how much typing (or tab-completing) you'll need to do. Deep, space-filled folder structures require more careful quoting and path management.
User permissions can prevent directory access. If a folder requires elevated privileges, a standard cd command will fail — you may need to run the terminal as an administrator (Windows) or use sudo in certain contexts (Linux/Mac).
Technical comfort level also plays a role. Beginners often find relative paths confusing at first, while experienced users build mental maps of their file systems and rarely need absolute paths for routine navigation.
Getting comfortable with cd takes a short period of deliberate practice, but the right approach depends on which shell you're using, which operating system you're on, and how your specific file system is structured.