DevOps · K8s · Volleyball · Travel  •  DevOps · K8s · Volleyball · Travel  •  DevOps · K8s · Volleyball · Travel
Explore NY Stream

Windows Command line

— ny_wk

Windows Command line

The Windows command line is the text-based interface (Command Prompt, or cmd.exe) that lets you control your PC by typing commands instead of clicking icons. This guide teaches the essential Windows command line commands every system administrator needs for navigation, file management, networking, and troubleshooting, plus the modern PowerShell and Windows Terminal tools that have largely replaced classic CMD.

What Is the Windows Command Line?

The Windows command line is a command interpreter: a program that reads lines of text you type and turns them into actions the operating system performs. The classic interpreter is the Command Prompt (cmd.exe), shipped with every version of Windows since Windows 2000 and still present in Windows 10 and Windows 11.

A command-line interface (CLI) feels archaic next to a graphical user interface (GUI), yet it remains indispensable for administrators. Many tasks are faster to type than to click, the CLI can be scripted and automated, and it works over remote sessions where no desktop is available. Windows inherited its CLI from MS-DOS, the disk operating system Microsoft licensed to IBM in 1981; modern Windows is built on the NT kernel, but the Command Prompt preserves DOS-style syntax for backward compatibility.

Today CMD is in maintenance mode. Microsoft recommends PowerShell for serious automation and Windows Terminal as the host application that runs CMD, PowerShell, and WSL side by side in tabs. The classic commands below still work everywhere, so they are the right place to start.

How to Open the Command Prompt

There are several ways to launch the Windows command line, and the method matters because some commands require administrator privileges:

  1. Press Win + R, type cmd, and press Enter for a standard prompt.
  2. For an elevated prompt, press Win + X and choose Terminal (Admin) on Windows 11, or type cmd in the Start menu and select Run as administrator.
  3. In any File Explorer window, type cmd in the address bar and press Enter to open a prompt already pointed at that folder.

You can tell an elevated session because the title bar reads Administrator. Commands that change system state (such as sfc, chkdsk, or service control) fail with "Access is denied" unless the window is elevated.

Navigating the File System

Every Command Prompt session has a current directory, shown in the prompt (for example C:\Users\Admin>). The first skills to master on the Windows command line are listing and moving between folders.

DIR — List Folder Contents

The dir command lists files and subdirectories. Useful switches:

  • dir /a — show hidden and system files too.
  • dir /s — recurse into every subfolder.
  • dir /o:d — sort by date; /o:s sorts by size.
  • dir /b — bare format (names only), ideal for scripting.

CD — Change Directory

Use cd to move around. A leading backslash means "from the drive root":

  • cd \Windows\System32 — jump to an absolute path.
  • cd .. — go up one level to the parent folder.
  • cd with no argument — print the current directory.
  • cd /d D:\Projects — the /d switch changes both the drive and the directory. Typing D: alone only switches the active drive.

Tab completion saves typing: start a name and press Tab to cycle through matches. This also handles spaces automatically, so cd \Program Files works without quotation marks in CMD (though quoting long paths is still a safe habit).

Essential File Management Commands

These Windows command line commands handle the day-to-day work of creating, copying, moving, and deleting files.

CommandPurposeExample
md / mkdirCreate a directorymd C:\Logs\2026
rd / rmdirRemove a directoryrd /s /q C:\Temp\old
copyCopy one or more filescopy report.txt D:\Backup
moveMove or rename filesmove *.log archive\
renRename a fileren old.txt new.txt
del / eraseDelete filesdel /q *.tmp
typePrint a text filetype notes.txt
attribView/set file attributesattrib +h secret.txt

Wildcards multiply the power of these commands. The question mark ? matches a single character, and the asterisk * matches any number of characters. For example, del test*.txt deletes every .txt file whose name begins with "test", and del *.txt deletes all text files in the current folder. Because del is irreversible and does not send files to the Recycle Bin, run dir with the same pattern first to preview exactly what will be affected.

XCOPY and ROBOCOPY — Power Copying

For folder trees, copy is too limited. Use xcopy or, better, Robocopy (Robust File Copy), which is built into modern Windows and is the administrator's preferred tool:

  1. Mirror a folder, copying only changed files and deleting extras in the destination:
    robocopy C:\Source D:\Backup /MIR
  2. Add /Z for restartable mode (survives network drops) and /R:3 /W:5 to retry three times with a five-second wait:
    robocopy C:\Source D:\Backup /MIR /Z /R:3 /W:5
  3. Robocopy returns exit codes 0-7 for success and 8 or higher for failure, which makes it script-friendly.

Networking and Diagnostics from the Command Line

Network troubleshooting is where the Windows command line shines. These commands diagnose connectivity problems quickly.

IPCONFIG — Show Network Configuration

ipconfig reports each adapter's IPv4 address, subnet mask, and default gateway. The most valuable variants for support work:

  • ipconfig /all — full detail including MAC address, DHCP server, and DNS servers.
  • ipconfig /release then ipconfig /renew — drop and re-request a DHCP lease.
  • ipconfig /flushdns — clear the DNS resolver cache, the classic fix for "the site loads on my phone but not my PC."

PING and TRACERT — Test Reachability

ping sends ICMP echo requests to confirm a host is reachable and measures round-trip time: ping 8.8.8.8 or ping google.com. Use ping -t for a continuous test (stop it with Ctrl + C).

When a host is unreachable, tracert maps the route hop by hop so you can see where the path breaks: tracert 8.8.8.8. Each line is one router ("hop"), and rows of asterisks indicate a device that did not respond. By default tracert tries up to 30 hops.

NSLOOKUP, NETSTAT, and NET

  • nslookup example.com — query DNS to confirm a name resolves to the expected IP.
  • netstat -ano — list active connections and listening ports with the owning process ID, so you can match a port to a program.
  • net use Z: \\server\share — map a network drive; net user, net localgroup, and net start manage accounts, groups, and services.

System, Disk, and Process Management

Administrators use the Windows command line to inspect hardware, repair disks, and control running programs.

Health and Repair Commands

  1. systeminfo — OS version, install date, RAM, and patch list in one screen.
  2. sfc /scannow — System File Checker scans and repairs corrupted Windows files (requires an elevated prompt).
  3. DISM /Online /Cleanup-Image /RestoreHealth — repairs the underlying component store that sfc relies on; run it first if sfc cannot fix everything.
  4. chkdsk C: /f — checks a disk and fixes errors. For the system drive it schedules the scan for the next reboot.

TASKLIST and TASKKILL — Manage Processes

tasklist lists every running process with its Image Name (the friendly program name) and its PID (Process Identifier, a unique number Windows assigns to each process). Because the list is long, pipe it to more to page through it:

tasklist | more

To end a stuck program, use taskkill. You can target it by PID or by image name, and add /f to force termination:

  • taskkill /pid 4812 /f — kill one process by ID.
  • taskkill /im notepad.exe /f — kill all instances of a program by name.

Redirection, Pipes, and Batch Files

The real power of the Windows command line comes from combining commands. Three operators do the heavy lifting:

  • Output redirection > writes a command's output to a file, overwriting it: ipconfig /all > netinfo.txt.
  • Append >> adds to the end of an existing file instead of replacing it: echo Done >> log.txt.
  • The pipe | feeds one command's output into another: tasklist | findstr chrome filters the process list to lines containing "chrome".

findstr is the built-in text-search tool (similar to grep on Linux). Combined with a pipe, it turns verbose output into exactly the line you need.

Writing a Simple Batch File

A batch file is a plain text file with a .bat extension containing commands that run in sequence. Create one with Notepad:

  1. Open Notepad and add the following lines: @echo off, then echo Backing up logs..., then robocopy C:\App\Logs D:\Backup\Logs /MIR /R:2, then echo Backup finished on %DATE% at %TIME%, then pause.
  2. Save it as backup.bat (set "Save as type" to All Files so Notepad does not add .txt).
  3. Double-click the file, or run it from any prompt by typing backup.bat.

@echo off hides the commands themselves so only their output shows. Environment variables such as %DATE%, %TIME%, %USERNAME%, and %PATH% let scripts adapt to the current machine. Set your own with set NAME=value and read it back as %NAME%.

Common Pitfalls and How to Avoid Them

  • Forgetting elevation. Repair commands fail silently or with "Access is denied" in a non-admin window. Always open Run as administrator for sfc, chkdsk, and service control.
  • Destructive wildcards. del *.* and rd /s /q do not use the Recycle Bin. Preview with dir first and double-check your current directory.
  • Spaces in paths. When scripting or passing paths to other tools, wrap them in quotes: cd "C:\Program Files\My App".
  • Confusing CMD with PowerShell. They share some commands but differ in syntax, variables, and quoting. Know which shell your window is running.
  • Assuming output went where you expected. > overwrites; use >> when you mean to append, or you will lose earlier results.

Verifying Your Commands Worked

Confirm results instead of assuming success:

  • After a copy or move, run dir on the destination to confirm the files arrived.
  • After ipconfig /flushdns, look for "Successfully flushed the DNS Resolver Cache."
  • After taskkill, run tasklist | findstr <name> and confirm the process is gone.
  • Check the errorlevel: type echo %errorlevel% immediately after a command. 0 means success; any non-zero value signals a problem worth investigating.

Key Takeaways

  • The Windows command line (cmd.exe) ships with every modern Windows version and remains essential for fast, scriptable administration.
  • Master navigation (cd, dir), file management (copy, robocopy, del), and networking (ipconfig, ping, tracert) first.
  • Redirection (>, >>) and pipes (|) combined with findstr turn raw output into precise answers.
  • Batch files and environment variables let you automate repetitive tasks reliably.
  • For new automation, learn PowerShell and run everything inside Windows Terminal, the modern host for all Windows shells.

Frequently Asked Questions

What is the difference between Command Prompt and PowerShell?

Command Prompt runs legacy DOS-style commands and simple batch scripts. PowerShell is a newer, object-oriented shell built for automation, with richer scripting, access to the entire .NET framework, and cmdlets like Get-Process instead of tasklist. CMD is fine for quick tasks; PowerShell is the choice for complex administration.

How do I open Command Prompt as administrator?

Type cmd in the Start menu, then click Run as administrator, or press Win + X and choose Terminal (Admin) on Windows 11. The title bar will read "Administrator" when elevation succeeds.

How can I see all running processes from the command line?

Run tasklist to list every process with its name and PID. Pipe it to more to page through the list, or to findstr to filter, for example tasklist | findstr chrome.

Is the Windows Command Prompt being removed?

No. Microsoft has moved CMD into maintenance mode and recommends PowerShell and Windows Terminal for new work, but cmd.exe and its classic commands still ship with Windows 11 and continue to work for backward compatibility.

For more hands-on Windows and system administration tutorials, subscribe to YouTube @explorenystream.