PowerShell Basics: Navigating Directories
Current Directory
- When you first open PowerShell, you'll be in your home directory.
- Prompt: Shows the current directory.
- PWD Command:
Print Working Directory command tells you which directory you are currently in.
Changing Directories
- CD Command:
Change Directory command used to change the current directory.
- Path Types:
- Absolute Path: Starts from the drive letter and specifies the entire path (e.g.,
C:\Users\Cindy\Documents).
- Relative Path: Uses part of the path relative to the current directory (e.g.,
CD .. to move up one level).
Navigating with CD
- Absolute Path Example:
- Command:
CD C:\Users\Cindy\Documents
- Changes to the Documents directory using the full path.
- Relative Path (Up One Level):
- Command:
CD ..
- Moves up one directory level.
- Combining Commands:
- From Documents to Desktop:
CD ..\Desktop
- Moves from Documents to Desktop using combined relative path.
Shortcuts
- Home Directory Shortcut:
CD ~ takes you to the home directory.
- Example to go to Desktop:
CD ~\Desktop
Tab Completion
- Feature: Auto-completes file names and directories when using the Tab key.
- Usage:
- Type the initial letter(s), press Tab to auto-complete.
- If incorrect, continue pressing Tab to cycle through options.
- Example:
- Typing
D and pressing Tab may cycle through Desktop, Documents, Downloads.
Notes
- The dot (
.) in paths like ./Desktop refers to the current directory.
- Tab completion is a valuable tool for efficient directory navigation.
These foundational skills in navigating directories using PowerShell can enhance efficiency and reduce errors while working with command lines.