🏴☠️ Becoming a Cap10 of the Command Line: Windows File System & Navigation
Objective: Teach absolute beginners how to confidently navigate and manage files in Windows using the command line (Command Prompt and PowerShell).
Part 1: Understanding the Windows File System
Before we dive into the command line, let’s get the big picture of how Windows organizes files.
Key Concepts:
- Drives (C:\, D:\, etc.): Windows organizes storage into drives.
- Folders (Directories): These are containers inside drives—just like on your desktop.
- Files: Individual items stored inside folders (e.g.,
.txt
,.exe
,.png
). - Paths: A file’s location on the system (e.g.,
C:\Users\John\Documents\report.txt
).
Example Structure:
C:\
├── Users\
│ ├── John\
│ │ ├── Documents\
│ │ ├── Downloads\
│ │ ├── Desktop\
│ │ ├── Pictures\
├── Program Files\
├── Windows\
├── Temp\
⏩ Now, let’s navigate this like a pro using the command line!
Part 2: Navigating the File System with CMD & PowerShell
First, open the Command Prompt or PowerShell:
- Command Prompt (cmd.exe): Press
Win + R
, typecmd
, and hit Enter. - PowerShell: Press
Win + X
and select Windows PowerShell.
1. See Your Current Location
CMD:
echo %CD%
PowerShell:
pwd # Returns the current directory
$PWD # PowerShell object way, same result as `pwd`
When to use: In CMD, echo %CD%
prints the current directory, and in PowerShell, pwd
gives the current directory. The $PWD
object is handy for scripts and interactive use.
2. List Files and Folders
CMD:
dir
PowerShell:
ls
When to use: Both commands list files in the current directory. Use dir /w
in CMD for wide format or apply filters in PowerShell.
3. Move Around (Change Directory)
CMD:
cd C:\Users\John\Documents # Move to Documents folder
cd .. # Move up one level
cd /d D:\Projects # Switch to another drive
PowerShell:
cd C:\Users\John\Documents # Move to Documents folder
cd .. # Move up one level
cd /d D:\Projects # Switch to another drive (works like CMD)
Set-Location C:\Users\John # Alternative PowerShell cmdlet
When to use: Use cd
in CMD and PowerShell; for clearer scripts in PowerShell, consider Set-Location
.
4. Create New Folders
CMD:
mkdir MyFolder
PowerShell:
mkdir MyFolder
New-Item MyFolder -ItemType Directory # Alternative in PowerShell
When to use: Both approaches create directories; PowerShell’s New-Item
provides extra control when needed.
5. Create Files
PowerShell:
New-Item myfile.txt -ItemType File
CMD:
echo "Hello World" > myfile.txt
When to use: PowerShell’s New-Item
is ideal for scripted workflows, while CMD’s redirection is great for quick file creation.
6. Delete Files and Folders
CMD:
del myfile.txt
rmdir MyFolder
PowerShell:
Remove-Item myfile.txt
Remove-Item MyFolder -Recurse
When to use: CMD uses del
and rmdir
, while PowerShell’s Remove-Item
can handle both files and folders with additional options.
7. Copy and Move Files
CMD:
copy myfile.txt C:\Backup\
PowerShell:
Move-Item myfile.txt C:\Backup\
Copy-Item myfile.txt C:\Backup\
When to use: Use CMD’s copy
or PowerShell’s Copy-Item
and Move-Item
for file operations with added flexibility.
Part 3: Intermediate Command Line Power Moves
Once comfortable, let's move to more intermediate commands.
1. Open Programs
CMD:
start notepad.exe
PowerShell:
start notepad.exe
2. Check Your Disk Space
CMD:
wmic logicaldisk get size,freespace,caption
PowerShell:
Get-PSDrive
3. Find Files Containing Specific Text
CMD:
findstr "error" log.txt
PowerShell:
Select-String -Path log.txt -Pattern "error"
4. Copy Multiple Files at Once
CMD:
copy *.txt C:\Backup\
PowerShell:
Copy-Item *.txt -Destination C:\Backup\
5. Clean Up Temp Files
CMD:
del /q C:\Users\%USERNAME%\AppData\Local\Temp\*
PowerShell:
Remove-Item "$env:LOCALAPPDATA\Temp\*" -Force -Recurse
Final Challenge: Prove Your Command Line Captaincy
Try these:
- Create a new folder called
Projects
insideDocuments
. - Create a file called
readme.txt
insideProjects
and write "Hello, Cap10!" inside it. - Rename the file to
info.txt
. - Move
info.txt
to theDesktop
. - Delete
info.txt
from theDesktop
. - List all
.txt
files in yourC:\Users\YourName\Documents\
folder.
Master these, and you're a Cap10 of the Command Line! 🏴☠️
Would you like a cheat sheet with all these commands for quick reference? 🚀
Key File Locations & Tools Available in the CLI
Now that you've learned how to navigate and manage files in the command line, it's important to understand where to find key system files and the tools you have access to in the CLI. Here's a breakdown of the most commonly used directories and utilities that will be helpful when you're working with files in Windows:
Key File Locations
Here are some important file locations in Windows that you will frequently interact with through the command line:
- C:\ - The root directory of the system. This is where your Windows installation resides, along with important folders like Program Files, Windows, and Users.
- C:\Users\YourName\ - Your personal user directory. This is where your documents, desktop files, and settings are stored.
- C:\Program Files (x86)\ - Contains installed programs (32-bit applications are usually stored here, while 64-bit apps are in C:\Program Files\).
- C:\Windows\ - The system directory containing all operating system files. Handle with care.
- C:\Temp\ - A folder for temporary files. Regular cleanup can free up space.
- C:\ProgramData\ - Stores application data shared between users (this folder is hidden by default).
- C:\Users\YourName\AppData\ - A hidden folder where applications store user-specific data like settings and cache.
Note: Use the cd
command with these paths (e.g., cd C:\Users\YourName\
) to quickly navigate.
Essential Command Line Tools
Here are some useful tools and utilities available in the Windows command line:
- dir - Lists the contents of a directory. Use
dir /s
ordir /b
for additional formats. - cd - Changes the current directory.
- mkdir - Creates a new directory.
- del - Deletes files (use
del /f
for force deletion). - copy - Copies files from one location to another.
- move - Moves files from one location to another.
- xcopy - Copies entire directories including subdirectories.
- robocopy - An advanced tool for copying files with options for resuming and network copying.
- findstr - Searches for text within files (similar to Linux's grep).
- choco - The Chocolatey package manager for installing or updating software.
- wmic - Retrieves system information, such as disk usage.
- tasklist - Displays all running processes.
- taskkill - Terminates a running process by name or PID.
Note: Most tools work in both CMD and PowerShell, though PowerShell cmdlets may offer extra features.
File Path Environment Variables
Environment variables let you access common directories without typing full paths. Examples include:
- %USERPROFILE% - Your personal user directory (
C:\Users\YourName\
). - %APPDATA% - Application settings directory (
C:\Users\YourName\AppData\Roaming\
). - %TEMP% - Temporary files directory (
C:\Users\YourName\AppData\Local\Temp
). - %PROGRAMFILES% - Directory for installed programs (
C:\Program Files
). - %WINDIR% - Windows system directory (
C:\Windows
).
Using these variables (e.g., cd %TEMP%
) can save you time.