Command Prompt (cmd) is a text-based command-line interpreter for Windows. Although more limited than PowerShell—which supports object-oriented scripting—cmd remains useful for legacy compatibility, simple file and process operations, and lightweight scripting.
Related to: Bash, PowerShell, bat
Summary Characteristics
- Text-Based Interface: Commands operate on plain text, without the object-passing capabilities of PowerShell.
- Limited Built-in Commands: Focused on core utilities like file handling, process control, and system inspection.
- Direct Execution: Commands are interpreted and executed line-by-line, without support for pipelines.
Navigating the File System
- Change Directory:
cd C:\path\to\directory - List Directory Contents:
dir - List in Bare Format:
dir /b
Managing Files and Directories
- Creating many folders
mkdir time_series_analysis
cd time_series_analysis
type nul > 01_data_prep.py
type nul > 02_exploration.py
type nul > 03_decomposition_stats.py- Create a Directory:
mkdir newfolder - Delete a Directory (with contents):
rmdir /s /q newfolder - Copy a File:
copy C:\source\file.txt D:\destination\ - Rename a File:
ren oldfile.txt newfile.txt - Delete a File:
del file.txt
Viewing System and Network Information
- Network Configuration:
ipconfig - Detailed System Info:
systeminfo
Managing Processes
- List Running Processes:
tasklist - Kill a Process by PID:
taskkill /F /PID 1234
Scripting with Batch Files
- Simple
.batScript Example:example.bat@echo off echo Hello, World! pause - Run the Script:
example.bat
Environment Variables
- View All Variables:
set - Set a Variable:
set MYVAR=Hello
Redirecting Output
-
Send Command Output to File:
dir > output.txt
Viewing Command History
-
Current Session Only:
doskey /history