How to navigate in cmd
Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.
Last updated: April 4, 2026
Key Facts
- The 'cd' command is used to change directories.
- The 'dir' command lists the contents of the current directory.
- Typing 'cd ..' moves you up one directory level.
- Typing 'cd \' (or 'cd C:\' for a specific drive) moves you to the root directory.
- Tab completion can auto-suggest file and directory names.
What is the Command Prompt?
The Command Prompt, often abbreviated as 'cmd', is a command-line interpreter application available in most Windows operating systems. It allows users to interact with the operating system by typing commands rather than using a graphical user interface (GUI). This makes it a powerful tool for performing tasks such as file management, system administration, and running scripts.
Basic Navigation Commands
Changing Directories: The `cd` Command
The most fundamental command for navigation is `cd`, which stands for 'change directory'. To move into a subdirectory, you type `cd` followed by the name of the subdirectory.
Example: If you are in the `C:\Users\YourName` directory and want to go into the `Documents` folder, you would type:
cd Documents
If the folder name contains spaces, you must enclose it in double quotes:
cd "My Documents"
To move back up one directory level (to the parent directory), you use `cd ..`:
cd ..
To go directly to the root directory of the current drive (e.g., `C:\`), you can use `cd \`:
cd \
To change to a directory on a different drive, you first need to switch to that drive by typing its letter followed by a colon, and then use `cd`.
Example: To move to the `Projects` folder on the `D:` drive:
D:
cd Projects
Listing Directory Contents: The `dir` Command
The `dir` command is used to display a list of all files and subdirectories within the current directory. This is equivalent to opening a folder in File Explorer and seeing its contents.
Example:
dir
The output of the `dir` command typically includes the date and time the files/directories were last modified, their size (for files), and their names.
There are several useful options for the `dir` command:
- `dir /p`: Displays the directory contents one screenful at a time.
- `dir /w`: Displays the directory contents in a wide format, listing multiple files/directories per line.
- `dir /s`: Displays files in the current directory and all subdirectories.
- `dir /a`: Displays files with specified attributes (e.g., `dir /a:h` shows hidden files).
Viewing the Current Directory: The `cd` Command (without arguments)
Simply typing `cd` and pressing Enter will display the full path of your current working directory.
Creating Directories: The `mkdir` Command
To create a new directory (folder), you use the `mkdir` (make directory) command, or its shorter alias `md`.
Example: To create a new folder named `NewProject`:
mkdir NewProject
Deleting Files and Directories: The `del` and `rmdir` Commands
To delete a file, use the `del` command followed by the filename.
Example: To delete a file named `old_report.txt`:
del old_report.txt
To remove an empty directory, use the `rmdir` command (or its alias `rd`).
Example: To remove an empty directory named `temp_folder`:
rmdir temp_folder
To remove a directory and all its contents (use with extreme caution!), you can use `rd /s`.
Example: To remove the `Backup` directory and everything inside it:
rd /s Backup
Advanced Navigation Tips
Tab Completion
One of the most helpful features for navigation is tab completion. As you start typing a command, filename, or directory name, press the Tab key. The Command Prompt will try to auto-complete the text for you. If there are multiple options, pressing Tab repeatedly will cycle through them. This saves typing and reduces errors.
Wildcards
Wildcards are special characters that can represent one or more other characters. The most common wildcards are:
- `*`: Represents zero or more characters. For example, `*.txt` matches all files ending with `.txt`. `My*` matches any file or directory starting with `My`.
- `?`: Represents a single character. For example, `file?.txt` would match `file1.txt`, `fileA.txt`, but not `file10.txt`.
Wildcards are useful with commands like `dir` and `del`. For instance, `dir *.log` would list all files with the `.log` extension.
Absolute vs. Relative Paths
When specifying a directory or file, you can use either an absolute path or a relative path.
- Absolute Path: This is the full path starting from the root of the drive (e.g., `C:\Program Files\MyApp`). It always points to the same location regardless of your current directory.
- Relative Path: This path is defined relative to your current working directory. For example, if you are in `C:\Users\YourName` and want to go to `Documents`, you can use the relative path `Documents`. If you wanted to go to `C:\Users\YourName\Desktop`, you could use the relative path `Desktop`.
Using `pushd` and `popd`
For more complex navigation, especially within batch scripting, the `pushd` and `popd` commands are useful. `pushd` changes to a directory and also stores the current directory in a special list. `popd` then returns you to the directory that was stored by `pushd`.
Understanding the Prompt
The command prompt itself usually displays your current location, followed by a `>` symbol. For example:
C:\Users\YourName>
This indicates that you are currently in the `C:\Users\YourName` directory.
When to Use the Command Prompt for Navigation
While File Explorer is excellent for everyday browsing, the Command Prompt offers advantages for specific tasks:
- Batch Processing: Automating repetitive file operations.
- Accessing Hidden Files/Folders: Some system files or folders are hidden by default in File Explorer but are easily accessible via `cmd`.
- Renaming Multiple Files: Using wildcards with `ren` or `move` commands.
- Troubleshooting: Running diagnostic tools or network commands.
- Working with Scripts: Executing batch files (`.bat`) or PowerShell scripts.
Mastering these navigation commands can significantly enhance your efficiency when working with the Windows operating system.
More How To in Daily Life
Also in Daily Life
More "How To" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
Missing an answer?
Suggest a question and we'll generate an answer for it.