Basic Commands - Windows: Changing Directories in the CLI
Navigating PowerShell
Opening PowerShell
- Typically opens in the home directory.
- The prompt displays the current directory.
PWD (Print Working Directory)
- Command to display the current directory.
- Example:
PWD
CD (Change Directory)
- Command to change the current directory.
- Requires specifying the path to change to.
Types of Paths
- Absolute Path: Specifies the complete path starting from the drive letter.
- Example:
C:\Users\Cindy\Documents
- Relative Path: Specifies the path relative to the current directory.
- Uses shortcuts to navigate.
Absolute Path Example
- To change to the documents directory from
C:\Users\Cindy, use:CD C:\Users\Cindy\Documents
Relative Path: Navigating Up One Level
CD ..- Takes you to the parent directory (one level up).
- Example:
- Current directory:
C:\Users\Cindy\Documents CD ..- New directory:
C:\Users\Cindy
Combining Relative Paths
- Moving up one level and then into another directory.
- Example:
- From
C:\Users\Cindy\Documents to C:\Users\Cindy\Desktop: - This is equivalent to first going to
C:\Users\Cindy using CD .. and then to C:\Users\Cindy\Desktop using CD Desktop.
Tilde (~) Shortcut
- The tilde represents the home directory path.
- Useful for quickly navigating to directories within the home directory.
- Example:
CD ~\Desktop takes you to the desktop directory in your home directory.
Tab Completion
- Feature to auto-complete file names and directory names by pressing the Tab key.
Usage
- Type the beginning of a file or directory name and press Tab.
- If multiple matches exist, press Tab repeatedly to cycle through the options.
- Example:
- Typing
d and pressing Tab may complete to Desktop if it's the first match. - Repeatedly pressing Tab cycles through matches like
Desktop, Documents, Downloads.
.\ prefix- Means the current directory.
- Example:
. \Desktop refers to the Desktop directory in the current directory. - Typing
de and pressing Tab will directly complete to Desktop if it's the only match.