Command Reference

Useful commands for Windows (CMD and PowerShell), Linux and macOS. Commands marked as needing Administrator or sudo will fail without it.

Windows Command Prompt (CMD)

ipconfig /allFull network configuration for every adapter.
ipconfig /flushdnsClear the DNS resolver cache.
ipconfig /release then ipconfig /renewDrop and request a new DHCP lease.
ping -n 4 example.comSend four echo requests to test connectivity.
tracert example.comShow each hop on the route to a host.
nslookup example.comQuery DNS for a hostname.
netstat -anoList active connections and listening ports with owning PIDs.
tasklistList running processes.
taskkill /PID 1234 /FForce-stop a process by its PID.
systeminfoOS version, hardware, install date and uptime.
whoami /allCurrent user, groups and privileges.
net userList local user accounts.
net localgroup administratorsList members of the local Administrators group.
sfc /scannowScan and repair protected system files (run as Administrator).
DISM /Online /Cleanup-Image /RestoreHealthRepair the Windows component store (run as Administrator).
chkdsk C: /fCheck the C: drive for errors and fix them (may require a reboot).
gpupdate /forceReapply Group Policy immediately.
where notepadFind the location of an executable on the PATH.
dir /s /b *.logRecursively list every .log file under the current folder.
shutdown /r /t 0Restart the computer immediately.

Windows PowerShell

Get-ComputerInfoDetailed system, OS and hardware information.
Get-NetIPConfigurationIP, gateway and DNS settings per adapter.
Test-NetConnection example.com -Port 443Test TCP reachability to a host and port.
Resolve-DnsName example.comDNS lookup with record type support.
Clear-DnsClientCacheClear the DNS client cache.
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10Top 10 processes by CPU time.
Get-Service | Where-Object Status -eq StoppedList all stopped services.
Restart-Service -Name SpoolerRestart a service by name (run as Administrator).
Get-WinEvent -LogName System -MaxEvents 20Show the 20 most recent System event log entries.
Get-LocalUserList local user accounts and their status.
Get-LocalGroupMember -Group AdministratorsList members of the local Administrators group.
Get-ChildItem -Recurse -Filter *.logSearch the current folder tree for .log files.
Get-Content C:\path\app.log -Wait -Tail 20Follow the end of a log file in real time (like tail -f).
Get-FileHash C:\file.iso -Algorithm SHA256Verify a file hash, for example after a download.
Get-DiskList physical disks and their health.
Invoke-WebRequest https://example.com -Method HeadFetch only the HTTP headers of a URL.
Get-Date -Format oCurrent date and time in ISO 8601 format.
Get-ExecutionPolicy -ListShow the script execution policy at each scope.

Linux

df -hDisk space used and free on each filesystem.
du -sh * | sort -hSize of each item in the current folder, sorted.
free -hMemory and swap usage.
uptimeSystem uptime and load averages.
top / htopLive view of processes and resource use.
ps aux | grep nginxFind running processes matching a name.
ss -tulpnListening TCP and UDP ports with owning processes.
ip a and ip rNetwork interfaces with addresses, and the routing table.
dig example.com +shortConcise DNS lookup.
curl -I https://example.comFetch only the HTTP response headers.
sudo systemctl status nginxCheck the status of a service.
sudo systemctl restart nginxRestart a service.
journalctl -u nginx -fFollow the logs for a specific service.
sudo apt update && sudo apt upgradeUpdate package lists and upgrade installed packages (Debian/Ubuntu).
grep -R "error" /var/logRecursively search files for a string.
find / -name "*.conf" 2>/dev/nullFind files by name, hiding permission errors.
lsof -i :80Show which process is using a port.
tar -czf backup.tar.gz folder/Create a compressed archive.
chmod 640 file / chown user:group fileChange file permissions or ownership.
last -n 10Show the last 10 logins.

macOS

sw_versmacOS version and build number.
system_profiler SPHardwareDataTypeHardware model, chip, memory and serial.
df -hDisk space used and free.
diskutil listList disks and partitions.
ipconfig getifaddr en0IP address of the Wi-Fi interface (en0).
networksetup -listallhardwareportsList network services and their device names.
scutil --dnsShow the DNS resolver configuration.
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponderFlush the DNS cache.
lsof -iTCP -sTCP:LISTEN -n -PList listening TCP ports and their processes.
pmset -g battBattery status and charge level.
caffeinate -dKeep the display awake until stopped with Ctrl+C.
softwareupdate -lList available macOS updates.
launchctl listList loaded launchd services.
log show --last 1h --infoShow unified log entries from the last hour.
brew update && brew upgradeUpdate Homebrew and upgrade installed packages.
open -a "Activity Monitor"Open an application from the terminal.
← Back to Home