How to Change Directory in Command Line (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 running scripts, managing files, or working with development tools, knowing how to move between directories efficiently saves time and opens up a much wider range of what you can do with your machine.
What "Changing Directory" Actually Means
Your operating system organizes files in a hierarchical tree structure — folders nested inside folders, branching out from a root location. When you open a terminal or command prompt, you're always positioned somewhere in that tree. That position is called your working directory.
Changing directory means moving your active position to a different folder so that commands you run apply to the right location. The primary command for this is cd — short for change directory — and it works across Windows, macOS, and Linux, though with some important differences in syntax and behavior.
The Basic cd Command
Moving Into a Subfolder
To navigate into a folder that exists inside your current location:
cd foldername If you're in your home directory and want to enter a folder called Documents, you'd type:
cd Documents Moving Up One Level
To go back up to the parent directory, use two dots:
cd .. You can chain these to go up multiple levels at once:
cd ../.. Navigating to an Absolute Path
Instead of moving step by step, you can jump directly to any location by providing the full path from the root of the file system:
- Windows:
cd C:UsersYourNameDocuments - macOS/Linux:
cd /home/yourname/documents
Absolute paths always work regardless of where you currently are in the directory tree.
Windows Command Prompt vs. PowerShell vs. Unix-Based Terminals 💻
The command differs slightly depending on which environment you're using.
| Environment | Shell | cd Works? | Notes |
|---|---|---|---|
| Windows Command Prompt | CMD | ✅ Yes | Requires /d flag to switch drives |
| Windows PowerShell | PowerShell | ✅ Yes | More Unix-like behavior |
| macOS Terminal | Zsh/Bash | ✅ Yes | Case-sensitive paths |
| Linux Terminal | Bash/Zsh/Fish | ✅ Yes | Case-sensitive paths |
| Git Bash (Windows) | Bash | ✅ Yes | Uses Unix-style paths (/c/Users/...) |
Switching Drives on Windows
A common point of confusion on Windows: cd alone won't move you to a different drive letter. If you're on C: and want to navigate to D:, you need the /d flag:
cd /d D:Projects Alternatively, just type the drive letter followed by a colon to switch drives first:
D: cd Projects On macOS and Linux, there are no drive letters — everything lives under a single root (/), so this isn't an issue.
Helpful Shortcuts That Speed Up Navigation 🗂️
The Home Directory Shortcut
On macOS and Linux (and in PowerShell/Git Bash on Windows), the tilde character is a shortcut for your home directory:
cd ~ This takes you directly to /home/username (Linux) or /Users/username (macOS) regardless of where you currently are.
Returning to the Previous Directory
On Unix-based systems and PowerShell, a hyphen takes you back to the last directory you were in:
cd - This is especially useful when switching back and forth between two locations.
Autocomplete with Tab
Most terminals support Tab completion — start typing a folder name and press Tab to auto-complete it. This reduces typos and speeds up navigation significantly. If there are multiple matches, pressing Tab twice usually shows your options.
Dealing With Spaces in Folder Names
Folder names containing spaces require special handling, otherwise the terminal interprets each word as a separate argument.
Wrap the path in quotes:
cd "My Documents" cd "/home/user/My Projects/Website" This applies across all platforms. Single quotes also work on Unix-based systems.
Useful Supporting Commands
Changing directories is more effective when you know what's around you:
pwd(macOS/Linux/PowerShell) — prints your current working directory so you always know where you arels(macOS/Linux) ordir(Windows CMD) — lists the contents of the current directoryls -la— shows hidden files and detailed info on Unix systemstree— displays a visual folder structure (available on both Windows and Linux/macOS with installation)
Where Individual Setup Makes a Difference
The mechanics of cd are consistent, but how navigation feels in practice varies considerably based on a few factors:
Operating system and shell: macOS defaulted to Zsh from Catalina onward; older Macs used Bash. Linux distributions vary widely — Ubuntu, Arch, Fedora each ship with different default shells and configurations. Windows users may be working in CMD, PowerShell, WSL (Windows Subsystem for Linux), or Git Bash, each of which handles paths and shortcuts differently.
File system case sensitivity: Linux file systems are typically case-sensitive, meaning Documents and documents are different folders. macOS and Windows are generally case-insensitive by default, though this can be configured. This matters when copying commands between systems.
Terminal customization: Many developers configure tools like Oh My Zsh, Starship, or Fish shell that add features such as smarter autocomplete, path abbreviation, or directory history — which can change how navigation works beyond the bare cd command.
Skill and workflow patterns: Someone running occasional commands benefits most from learning absolute paths and Tab completion. A developer spending hours daily in the terminal might invest in shell plugins, aliases (alias docs="cd ~/Documents"), or tools like zoxide that learn your most-visited directories and let you jump there with a short keyword.
The right approach to command line navigation ultimately depends on which shell you're running, how your file system is structured, and how much of your work happens in the terminal — making your own setup the key variable worth examining.