Master the primary interface for IT professionals. Learn to navigate filesystems, manipulate files, and automate tasks using Windows CMD and PowerShell.
The Command Prompt (CMD) is the legacy Windows shell. While older, it's still widely used for simple tasks and legacy scripts.
C:\Users\Student> dir
C:\Users\Student> cd Documents
C:\Users\Student\Documents> cls
C:\Users\Student\Documents> cd ..
dir: List files and directories in current locationcd (Change Directory): Move between folderscls: Clear the screenchdir: Display the name of the current directoryViewing and managing files directly without a GUI.
C:\> echo Hello IT Support > test.txt
C:\> type test.txt
C:\> copy test.txt backup.txt
C:\> move backup.txt C:\Temp\
C:\> del test.txt
echo: Output text or create filestype: Display the contents of a text filecopy / move: File operationsdel: Delete filestree: Graphical display of folder structureA user needs a list of every file in a specific folder including subfolders. You can't manually copy-paste names. Use dir /s > filelist.txt to export the entire structure to a text file for them.
PowerShell is built on .NET and uses a predictable Verb-Noun naming convention for cmdlets.
PS C:\> Get-ChildItem
PS C:\> Set-Location -Path "C:\Windows"
PS C:\Windows> Get-Command *Service*
Get-ChildItem (gci): The PS equivalent of dirSet-Location (cd): Change directoriesGet-Help: Your best friend for learning flags and syntaxIn CMD, pipes pass text. In PowerShell, pipes pass **Objects**. This allows for powerful filtering.
PS C:\> Get-Service | Where-Object {$_.Status -eq "Running"}
PS C:\> Get-Process | Sort-Object CPU -Descending | Select-Object -First 5
Get-Service: List all Windows servicesGet-Process: List running applicationsStart-Process / Stop-Process: Control applications$ (e.g., $myVar = "Data")Get-Process | Select-Object Name, CPU, WorkingSet | Sort-Object CPU -Descending | Select-Object -First 10.Get-Process notepad | Stop-Process to kill it.Understanding where you are and how to point to other locations is critical.
C:\Users\Admin\Desktop\notes.txt)..\Documents\report.pdf). refers to current directory, .. refers to parent directoryWhile similar, notice the slash direction and drive letters.
| Feature | Windows (CMD/PS) | Linux (Bash) |
|---|---|---|
| Root | C:\ |
/ |
| Slash | Backslash (\) |
Forward Slash (/) |
| Home | %USERPROFILE% |
~ |
| List Files | dir |
ls |
Manipulate groups of files with ease.
*: Matches any number of characters (del *.tmp)?: Matches exactly one character (copy image??.jpg folder/)>: Overwrite file with output (ipconfig > network.txt)>>: Append output to end of file (date >> log.txt)|: Pipe - Send output of one command as input to anotherWhat command would you use to list all files ending in .log and save that list to a file named audit.txt without deleting what's already in audit.txt?
dir *.log >> audit.txt (or Get-ChildItem *.log >> audit.txt in PowerShell)
If you need to restart a service on 100 remote Windows machines, use PowerShell (Invoke-Command). If you need to check if a local file exists in a simple batch file, CMD is fine. If you are managing a web server running Ubuntu, use Bash.
Lab_Foundation on your desktop.Docs, Logs, Backup.Docs named info.txt containing your name.info.txt to Backup using only the command line.network_info.txt.type to verify the content.Export-Csv.| Action | CMD | PowerShell |
|---|---|---|
| List Files | dir |
Get-ChildItem |
| Copy File | copy |
Copy-Item |
| Move File | move |
Move-Item |
| Delete File | del |
Remove-Item |
| Make Directory | mkdir |
New-Item -ItemType Directory |
| Network Config | ipconfig |
Get-NetIPAddress |
It moves the current terminal session up one level to the parent directory.
'>' overwrites the destination file with new output, while '>>' appends the output to the end of the existing file.
PowerShell. It passes structured objects through the pipeline rather than just plain text strings.
Use the Get-Help cmdlet followed by the command name (e.g., Get-Help Get-Service).