WIN: Windows Command Line (CMD)

A practical reference for the Windows Command Prompt (CMD) covering its advantages over GUI, environment variables, system information commands, networking tools, file and disk management, task management, and other essential utilities.

Why Use the Command Line?

The Windows Command Prompt (CMD) offers several advantages over the graphical interface:

  • Lower resource usage — CLIs require fewer system resources than graphics-intensive GUIs. This is particularly valuable for older hardware, systems with limited memory, or cloud environments where lower resources mean lower costs.
  • Automation — Creating a batch file or script with the commands you need to repeat is far easier than automating GUI interactions.
  • Remote management — CLI makes it very convenient to use protocols like SSH to manage a remote system such as a server, router, or IoT device. This works well on slow network speeds and systems with limited resources.

Environment and System Info

Commands can only be issued within the Windows Path. To check your current path:

cmd
set

Example output:

cmd
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\user\AppData\Roaming
CommonProgramFiles=C:\Program Files\Common Files

OS Version

cmd
ver

System Information

cmd
systeminfo

Example output:

cmd
Host Name:                 WINSRV2022-CORE
OS Name:                   Microsoft Windows Server 2022 Datacenter
OS Version:                10.0.20348 N/A Build 20348
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Server

Help and Pagination

  • help — Provides help information for a specific command.
  • cls — Clears the Command Prompt screen.

For long output, pipe it through more to view page by page:

cmd
driverquery | more

Press the spacebar to page through. Exit with Ctrl + C.

Use /? with most commands to display help:

cmd
netstat /?


Network Commands

Check Network Configuration

cmd
ipconfig

cmd
ipconfig /all

Test Connectivity

cmd
ping google.com

Sends ICMP packets and waits for a response. If a response is received, you can reach the target and the target can reach you.

Trace Network Route

cmd
tracert google.com

Traces the network route to reach the target by monitoring routers along the path.

DNS Lookup

cmd
nslookup example.com

Looks up a host or domain and returns its IP address using the default name server.

Specify a DNS record type:

cmd
nslookup --type=MX example.com

View Active Connections

cmd
netstat

Displays current network connections and listening ports. Flags:

FlagDescription
-aDisplays all established connections and listening ports
-bShows the program associated with each port/connection
-oReveals the process ID (PID) associated with the connection
-nUses numerical form for addresses and port numbers

Combined:

cmd
netstat -abon


File and Disk Management

Current Directory

cmd
cd

Displays the current drive and directory (equivalent to pwd in Linux).

List Directory Contents

cmd
dir

cmd
dir /a

Includes hidden and system files.

cmd
dir /s

Displays files in the current directory and all subdirectories.

Visualize Directory Tree

cmd
tree

Create and Remove Directories

cmd
mkdir foldername

cmd
rmdir foldername

File Operations

CommandDescription
typeView content of a text file
copyCopy a file
moveMove a file
delRemove files
eraseRemove files (alias for del)

Task and Process Management

List Running Processes

cmd
tasklist

Filter by process name:

cmd
tasklist /FI "imagename eq sshd.exe"

/FI sets a filter — in this case, image name equals sshd.exe.

Terminate a Process

cmd
taskkill /PID 4567


Other Useful Commands

CommandDescription
chkdskChecks the file system and disk volumes for errors and bad sectors.
driverqueryDisplays a list of installed device drivers.
sfc /scannowScans system files for corruption and repairs them if possible.
shutdown /sShuts down the system.
shutdown /rReboots the system.
shutdown /aCancels a pending shutdown or reboot.

Using `more`

Display a text file page by page:

cmd
more file.txt

Pipe long command output:

cmd
driverquery | more


Quick Reference Summary

text
Network:
  ipconfig        - Network config
  ipconfig /all   - Full network config
  ping            - Test connectivity
  tracert         - Trace route
  nslookup        - DNS lookup
  netstat -abon   - Active connections + PIDs

Files:
  cd              - Current dir (like pwd)
  dir             - List dir (like ls)
  mkdir / rmdir   - Create/remove directory
  type            - View file content
  copy / move     - Copy/move files
  del / erase     - Delete files

Processes:
  tasklist        - List running processes
  taskkill /PID   - Terminate process by PID

System:
  ver             - OS version
  systeminfo      - Full system info
  set             - Environment variables
  chkdsk          - Disk check
  sfc /scannow    - System file check


Summary

The Windows Command Prompt provides a powerful, low-overhead interface for system administration, automation, and remote management. Mastering commands across networking (ipconfig, netstat, ping, tracert), file management (dir, copy, move, del), and process control (tasklist, taskkill) forms the foundation of effective Windows administration from the command line.