Beginner’s Guide to File and Folder Operations: Command Prompt (CMD) and PowerShell
Introduction to Command-Line Interfaces
Before diving into the commands, it’s crucial to understand what these environments are:
- CMD (Command Prompt): The traditional command-line interface for Windows, supporting a wide range of legacy and modern file operations.
- PowerShell: A more recent, powerful, object-oriented shell and scripting language from Microsoft, now cross-platform and the preferred tool for Windows automation and system management.
- Zsh (Z shell): An advanced Unix shell, now standard on macOS, bringing enhancements over Bash such as better tab completion and powerful scripting features2.
Each has a slightly different syntax and philosophy, but all can accomplish core tasks like changing directories, listing files, creating/deleting files and folders, and more.
Quick Syntax Overview
To provide a clear high-level comparison, here’s a table summarizing the basic commands:
|
Operation |
CMD |
PowerShell |
Zsh (macOS) |
|
List contents |
dir |
Get-ChildItem or ls |
ls |
|
Change directory |
cd [path] |
Set-Location [path] or cd [path] |
cd [path] |
|
Up one level |
cd .. |
cd .. |
cd .. |
|
Make directory |
mkdir [name] or md [name] |
New-Item -ItemType Directory -Path [name] or mkdir [name] |
mkdir [name] |
|
Remove directory |
rmdir [name] or rd [name] |
Remove-Item -Recurse [name] |
rm -r [name] |
|
Remove file |
del [file] or erase [file] |
Remove-Item [file] |
rm [file] |
|
Create empty file |
type nul > file.txt |
New-Item file.txt -ItemType File |
touch file.txt |
|
Edit text file |
notepad file.txt / copy con |
notepad file.txt / Set-Content |
nano file.txt / vim file.txt |
|
Open file (default app) |
start filename.txt |
Invoke-Item filename.txt / ii |
open filename.txt |
|
List all (incl. hidden) |
dir /a |
Get-ChildItem -Force |
ls -a |
|
Remove file |
del file.txt |
Remove-Item file.txt |
rm file.txt |
|
New empty file |
type nul > note.txt |
New-Item note.txt -ItemType File |
touch note.txt |
|
Add line to file |
echo Hello > note.txt |
Set-Content note.txt “Hello” |
echo Hello > note.txt |
|
Append to file |
echo World >> note.txt |
Add-Content note.txt “World” |
echo World >> note.txt |
|
Edit file |
notepad note.txt |
notepad note.txt or Set-Content |
nano note.txt |
|
Open file (def) |
start note.txt |
Invoke-Item note.txt or ii note.txt |
open note.txt |
***Note: PowerShell aliases many classic commands (e.g., cd, ls, mkdir) to its cmdlets for ease of transition, but the underlying mechanisms and capabilities are richer, particularly if you use cmdlets directly.
