The `cd` command in the terminal is your fastest way to switch between folders on Linux, macOS, or Windows (Command Prompt/PowerShell). It lets you navigate to any directory—whether a subfolder in your home, a network drive, or a remote server—without leaving your command line. No mouse or GUI needed: just type the path, and `cd` does the rest. First, ensure you have a terminal open (Terminal on macOS/Linux, Command Prompt/PowerShell on Windows), and your system must support basic file paths or use a shell (like Bash, Zsh, or PowerShell).
What You'll Need
- An installed terminal emulator (Terminal on macOS/Linux, Command Prompt/PowerShell on Windows).
- Basic familiarity with file paths (e.g., `~/Documents` or `C:\Users\You`).
- A shell that supports `cd` (all modern terminals do, including macOS/Linux Bash, PowerShell, and Windows Command Prompt).
Step-by-Step
-
Open your terminal. On macOS/Linux, press
Cmd+Spaceto launch Terminal. On Windows, open Command Prompt (search in Start) or PowerShell. Important: Your current directory is displayed at the prompt (e.g.,user@host:~$for Bash,C:\> for Command Prompt). This tells you where the shell is "looking" for commands. -
Use relative paths (e.g., go up or into a folder). Type commands like these:
cd ..— Move up one directory level (e.g., from `/home/user/Documents` to `/home/user`).cd .— Stay in the current folder (useful for listing files withlsordir).cd ./subfolderorcd subfolder/— Enter a subfolder in the same directory.cd ~/Downloads— Jump to yourDownloadsfolder (home directory shortcut).
cd journal. -
Use absolute paths (full directory names). Enter any path from the root (e.g.,
cd /home/user/Documentsfor macOS/Linux,cd C:\Users\You\Documentsfor Windows). Absolute paths work from anywhere in your filesystem. Tip: For Windows paths, use forward slashes or double backslashes:cd C:/Users/You/Documentsorcd C:\\Users\\You\\Documents. -
Navigate remote servers or network drives. Connect to a remote machine (e.g., `ssh user@server`) or mount a network folder (e.g., `net use Z: \\server\share` on Windows). Then use:
cd /remote/path(Linux/macOS) orcd Z:\remote\path(Windows).- Use `~` for the remote user’s home folder (e.g.,
cd ~user).
-
Check your current directory before proceeding. Type:
- Linux/macOS:
pwd(Print Working Directory). - Windows:
cd(shows current path) orecho %cd%in PowerShell.
- Linux/macOS:
Common Mistakes
-
Typo in the path. For example,
cd ~/Documents` instead ofcd ~/Documents. Use your terminal’s autocompletion (holdTaborCtrl+P) to fix typos. -
Forgetting slashes or spaces. Windows paths must use:
- Forward slashes:
cd /path/to/folder(works in Bash/PowerShell). - Double backslashes:
cd C:\path\to\folder(Command Prompt).
cd My Foldersfails; usecd "My Folders"orcd My\ Folders. - Forward slashes:
-
Access denied permissions. Try:
- Run the terminal as an admin (Windows) or use `sudo` (Linux/macOS) before `cd`.
- Check if the folder exists with
ls(Linux/macOS) ordir(Windows).
-
Using the wrong shell. For example, if you’re in PowerShell and type
cd ~, it may fail due to PowerShell’s path handling. UseSet-Locationorcd ~explicitly in PowerShell.
Tips
-
Shortcuts for frequently used folders. Add these to your shell config (e.g.,
.bashrcor~/.zshrc):- Alias
d=~/Documents→ Typecd dto jump to Documents. - Alias
v=~/Videos→ Typecd v.
- Alias
-
Use `cd` with wildcards. For example:
- Linux/macOS:
cd *project*(goes into any folder with "project" in its name). - Windows:
cd *.txt(goes into a folder containing a file named "*.txt").
- Linux/macOS:
-
History navigation. Press
Up Arrowto repeat last commands, or use:- Linux/macOS:
cd $(history | tail -1 | awk '{print $2}')(go to the last directory you changed to). - PowerShell:
cd $PWD(stays in current folder).
- Linux/macOS:
-
Windows-specific tip. Use
cd "path with spaces"with quotes or backslashes to avoid errors. For example:cd "C:\Users\You\My Project"orcd "My Project"(if in the same folder as the project).
Troubleshooting
-
`cd` doesn’t work. Check these first:
- Is your terminal open? Close and reopen.
- Are you logged in? Log out and back in (or restart the terminal).
- Is the path correct? Use
pwd(Linux/macOS) orecho %cd%(Windows) to verify. - Does the folder exist? Run
ls(Linux/macOS) ordir(Windows) to confirm.
-
Permission denied (Linux/macOS). Try:
- Run with
sudo(use sparingly):sudo cd /path. - Add the folder to your
~/.bashrcor~/.zshrcand reload withsource ~. - Check ownership:
ls -l /path(should show you as owner).
- Run with
-
Windows: `cd` fails with "The system cannot find the path". Possible fixes:
- Use forward slashes:
cd /path/to/folder. - Escape spaces:
cd "C:\My Folder". - Check if the folder exists:
dir "C:\My Folder". - Use the full UNC path:
cd \\server\sharefor network drives.
- Use forward slashes:
-
Remote server connection. If using SSH (e.g.,
ssh user@server), ensure:- The SSH server is running.
- You have SSH keys set up (or a password, but avoid typing).
- You’re in the correct directory after logging in (e.g.,
cd /home/user).
lsorpwdafter connecting. -
PowerShell vs. Command Prompt. PowerShell handles paths differently than Command Prompt:
- Use
Set-Locationinstead ofcd. - Forward slashes work:
Set-Location /path/to/folder. - Check current path:
Get-Location.
- Use
Frequently Asked Questions
How do I change directory in PowerShell?
In PowerShell, useSet-Location instead of cd. For example:
Set-Location "C:\My Folder" or Set-Location ~/Documents. Use Get-Location to check your current directory.
Why does cd fail on Windows paths with spaces?
Windows requires quotes around paths with spaces (e.g., cd "C:\My Folder") or double backslashes (e.g., cd C:\My\Folder). Forward slashes also work in PowerShell but may cause issues in older Command Prompt versions.
How can I go back to my home directory quickly?
Usecd ~ (Linux/macOS/PowerShell) or cd \ (Command Prompt on Windows). The tilde (~) is a shortcut for your home folder.
What if I don’t know the full path to a folder?
Start from the current directory and use relative paths:- Move up:
cd ... - List files:
ls(Linux/macOS) ordir(Windows). - Navigate:
cd folder_name(if it’s in the current folder).
Can I use cd in a batch file?
Yes, but with limitations. Use:
cd "C:\My Folder" (for paths with spaces) or cd /d C:\My\Folder (Command Prompt). In PowerShell, use Set-Location.
Why does cd say "No such file or directory" on macOS/Linux?
Check these:
- Is the folder listed when you run
ls? - Is the path correct? Use
pwdto verify. - Are you logged in as the correct user? Try
sudo chdir /path(last resort). - Is the folder in a different filesystem? Use
mountto check.