Command-line diagnostic tools give you a fast, scriptable, and reliable way to investigate system and network issues without relying on GUI utilities that may not be available in all environments. This reference organises the most important diagnostic commands by category, with syntax examples and notes on what to look for in the output. Where Windows and Unix-based (macOS/Linux) commands differ, both variants are shown side by side.
Network Diagnostics
Network diagnostic commands help you verify connectivity, resolve DNS names, trace packet routes, and inspect active connections.
Ping — Test Basic Connectivity
Ping sends ICMP echo requests to a target host and measures the round-trip time. It confirms whether a host is reachable and whether there is packet loss.
Key flags:
-n <count> (Windows) / -c <count> (macOS/Linux): Send a specific number of packets
-t (Windows): Ping continuously until stopped with Ctrl+C
-i <interval> (Linux/macOS): Set interval between packets in seconds
What to look for: Request timed out indicates the host is unreachable or blocking ICMP. High latency or intermittent packet loss suggests a network path issue.
Tracert / Traceroute — Trace Packet Route
Tracert (Windows) and traceroute (macOS/Linux) show each hop a packet takes to reach its destination, helping you identify where in the network path a failure or delay is occurring.
Key flags:
-d (Windows) / -n (Linux): Do not resolve IP addresses to hostnames (faster)
-h <max_hops> (Windows): Set maximum hop count (default 30)
What to look for: Asterisks (* * *) at a specific hop indicate packet loss at that hop. High latency at one hop that does not improve in subsequent hops often points to a congested or mis-configured router at that point.
What to look for:
- Check the assigned IP address, subnet mask, and default gateway
- Look for
169.254.x.x (APIPA) addresses, which indicate DHCP has failed
- Use
ipconfig /flushdns to clear the local DNS cache when resolving stale DNS records
NSLookup queries DNS servers to resolve names to IP addresses or look up specific DNS record types.
What to look for: Compare the result from your local DNS server against a public DNS server (e.g., 8.8.8.8) to determine if a DNS resolution issue is local or global. Use dig +trace to follow the full delegation chain from root servers.
Netstat — Active Connections and Listening Ports
Netstat displays active TCP/UDP connections, listening ports, and associated process IDs.
Key flags:
-a: Show all connections and listening ports
-n: Show addresses as numbers (no DNS lookup)
-o (Windows): Show owning process ID
-b (Windows): Show the executable involved in each connection
-p (Linux): Show the process using the socket
What to look for: Identify unexpected listening ports or connections to unknown remote addresses that could indicate a misconfiguration or malicious process.
Test-NetConnection / Curl — Port-Level Connectivity
What to look for: TcpTestSucceeded: True (Windows) or succeeded (nc) confirms the port is open and the service is listening. Failures indicate a firewall block, service not running, or wrong port.
Disk & Storage
CHKDSK — Check Disk for Errors
CHKDSK scans the file system and disk surface for errors and optionally repairs them.
Key flags (Windows):
/f: Fix errors on the disk
/r: Locate bad sectors and recover readable information (includes /f)
/x: Force the volume to dismount first
Running chkdsk /r on a live system volume requires a reboot. The scan runs during the next startup and can take several hours on large drives.
SMART Status — Drive Health
Self-Monitoring, Analysis and Reporting Technology (SMART) data gives early warning of drive failures.
What to look for:
SMART overall-health self-assessment test result: PASSED — drive is healthy
FAILED! — replace the drive immediately and recover data
- Attributes with high
RAW_VALUE on: Reallocated_Sector_Ct, Pending_Sector_Count, Uncorrectable_Sector_Count
DF / DU — Disk Free Space and Usage
Key flags (Unix):
df -h: Show disk free space in human-readable format
du -sh <path>: Show total size of a directory
--max-depth=1 / -d 1: Limit depth to one level
Windows-Specific Commands
SFC — System File Checker
Scans protected Windows system files for corruption and replaces damaged files.
Results are logged to %windir%\Logs\CBS\CBS.log. Look for lines containing [SR] for System File Checker activity. If SFC reports it cannot fix certain files, run DISM first.
DISM — Deployment Image Servicing and Management
DISM repairs the Windows Component Store, which SFC depends on. Run DISM before SFC when SFC fails to repair files.
Sequence to run when dealing with system file corruption:
Windows Event Log Queries
GPResult — Group Policy Results
Use /h to generate an HTML report, which is the most readable format for reviewing applied policies. Open the resulting file in a browser.
msinfo32 provides a comprehensive snapshot of hardware, software, and system configuration, including installed drivers, running services, and IRQ/port assignments.
macOS-Specific Commands
Linux-Specific Commands
On Linux systems running systemd, journalctl is the primary log tool. Use journalctl -b -1 to view logs from the previous boot — particularly useful when investigating a system that crashed and was rebooted.